Linq query to perform a full text search - linq

How can the following be done with a linq statement?
SELECT Description
FROM Production.ProductDescription
WHERE FREETEXT(Description, 'Some Keywords')

No, the full text search function FREETEXT in TSQL is not directly accessible with Linq to SQL.
You would have to execute that query directly in a database function, then you can pull your result set back with Linq to SQL.

I am not sure, but you might have to search each column/property of the table against your keyword to mimick freetext.
ex:
context.Production.ProductDescription
.Where(pd=>pd.Property1.Contains("Keyword") || pd.Property2.Contains("Keyword");

Related

How to create Interactive/Classic Report with dynamic SQL?

I'm running Apex 19.2 and I would like to create a classical or interactive report based on dynamic query.
The query I'm using is not known at design time. It depends on an page item value.
-- So I have a function that generates the SQL as follows
GetSQLQuery(:P1_MyItem);
This function may return something like
select Field1 from Table1
or
Select field1,field2 from Table1 inner join Table2 on ...
So it's not a sql query always with the same number of columns. It's completely variable.
I tried using PL/SQL function Body returning SQL Query but it seems like Apex needs to parse the query at design time.
Has anyone an idea how to solve that please ?
Cheers,
Thanks.
Enable the Use Generic Column Names option, as Koen said.
Then set Generic Column Count to the upper bound of the number of columns the query might return.
If you need dynamic column headers too, go to the region attributes and set Type (under Heading) to the appropriate value. PL/SQL Function Body is the most flexible and powerful option, but it's also the most work. Just make sure you return the correct number of headings as per the query.

DB::getQueryLog() not printing groupby

I have this query to be printed in normal SQL query:
Brand::get()->groupBy('name');
print_r(DB::getQueryLog());
but it is displaying only select * from brands ignoring groupBy. Why is it ignored?
You're grouping after executing the query. The correct way to see your desired result:
Brand::groupBy('name')->get();
print_r(DB::getQueryLog());
What you're doing is executing the groupBy on a Collection. This is working also but it's laravel that is grouping and not your database. That's why you won't see the groupBy command in the SQL query.
you can also use
Brand::groupBy('name')->toSql();
This will print sql query.

How to put a raw SQL query in Sequel

I am trying to convert SQL code to Seqel to run it from my script. How do I convert this:
select code, count(1) as total
from school_districts
group by code order by total desc;
into Sequel? Or, is there a way to pass raw SQL to Sequel? Also the school_districts will be interpolated #{table_name}.
DB[:school_districts].select(:code).group_and_count(:code).reverse_order(:count)
is a Sequel way of executing that query. I did not however alias the count column, but I hope you can do with this.
Even though working in Sequel is preferable as it allows you to change DBMs without changing your code I would prefer you use the fetch method.
You can do it a couple ways:
Use []:
DB["your sql string"]
Use fetch:
DB.fetch("your sql string")

function in where clause+ axapta2009

I am having Illegal use of WHERE expression for the following statement
select dateField from tableName
where dayname(dayofwk(tableName.dateField)) like 'sunday';
Pls help
Anthony is right, of course. However, there are still at leat 2 options to acheive the same result.
Create a new integer field in your table. This field should store the return value of the dayOfWk() function. Later you can easily query this table.
Second option - create a View inside AX and use a computed column feature toghether with the datePart() SQL Server function. Something like datepart(dw, tableName.DateField) should do it.
The first option will probably result in better performance.
You cannot use a function in a where clause, or in any select statement
you can't use any function on any field of the same table for which you are using the query

how to make query in Oracle - like Access

In access I can make a query (1) that returns something
and make another query (2) that uses the first query (1).
How I can do it in Oracle 11g ?
thanks in advance
I am not an expert in Oracle but you should check out Views and Nested Views in Oracle.
In lack of more information about what to achieve, see the syntax of
Insert with Select and Subquery
Update Statements
Not sure what your question is, but you can use the WITH clause to create "views" within a query - no need to create a VIEW and in 11g you can use recursive sub-query using the WITH clause.

Resources