i fail while converting this sql to linq...
hope anybody do it.
SELECT Max([PersonalNumber]+1)
FROM TestTable
GROUP BY CalYear
HAVING CalYear=Year(Now())
Thanks.
The HAVING clause is there to enable you to filter on the results of an AGGREGATE. In this instance you are filtering on the GROUP column which could just be filtered using a WHERE clause instead.
Therefore you do not need to produce a HAVING clause in LINQ. A simple WHERE clause will do the same.
check out here --> http://blogs.msdn.com/vbteam/archive/2007/12/18/converting-sql-to-linq-part-5-group-by-and-having-bill-horst.aspx
From TestTable in a
Group By CalYear
into CalYear = Year(Now())
Related
How to write a DQL script for getting the case insensitive string values using order by.
select *from country order by lower(name) giving me error. Thanks for your help in advance
I have a problem when try extract ddl for sequence using this function in this query:
select dbms_metadata.get_dependent_ddl('SEQUENCE', base_object_name) from dual;
base_object_name - name of trigger, that use sequences.
Result: ora-31604 invalid name parameter NAME "BASE_OBJECT_NAME" for OBJECT_TYPE 'SEQUENCE'
For example when I execute this query:
select dbms_metadata.get_dependent_ddl('INDEX', base_table_name) from dual;
in result I have indexes for specified table.
Please, help, how to extract sequence ddl using get_dependent_ddl() function?
Sequences are not dependent on tables, therefore you need to use select dbms_metadata.get_ddl('SEQUENCE', 'SEQ_NAME') from dual; to retrieve its ddl.
A sequence is not dependent on a trigger. It is a separate object that requires no other object in order to exist. Use the GET_DDL subprogram on DBMS_METADATA instead:
select dbms_meta_data.get_ddl('SEQUENCE',sequence_name) from dual
I have a DOB column in a table that is currently in use. See below.
I want to select just the Year from that DOB and display that on a Listbox (or any appropriate interface on a page). We are not using SPs. So I will probably coding SQL directly from the page or using SQL datasource. Using LINQ is alright if that can be done in it.
So please someone suggests me how this can be done.
Thanks a lot.
Use the YEAR function in your SQL statement.
SELECT YEAR([DateOfBirth])
FROM MyTable
SELECT DISTINCT Year(DateOfBirth) AS Year FROM MyTable ORDER BY Year
By including the DISTINCT keyword you will prevent duplicates in your list and by adding the ORDER BY clause the years will be sorted ascending. You can then bind the result to your listbox.
In your TSQL, write this:
SELECT YEAR(DateOfBirth), ...
FROM ...
I have a trivial issue that I can't resolve. Currently our app uses Linq to retrieve data and get a basic integer value of the row count. I can't form a query that gives back a count without a 'select i'. I don't need the select, just the count(*) response. How do I do this? Below is a sample:
return (from io in db._Owners
where io.Id == Id && io.userId == userId
join i in db._Instances on io.Id equals i.Id **select i**).Count()
;
The select i is fine - it's not actually going to be fetching any data back to the client, because the Count() call will be translated into a Count(something) call at the SQL side.
When in doubt, look at the SQL that's being generated for your query, e.g. with the DataContext.Log property.
Using the LINQ query syntax requires a select statement. There's no way around that.
That being said, the statement will get transformed into a COUNT()-based query; the select i is there only to satisfy the expression system that underlies the LINQ query providers (otherwise the type of the expression would be unknown).
Including the select will not affect the performance here because the final query will get translated into SQL. At this point it will be optimized and will be like select (*) from ......
Maybe i should do this in C# but i have more then one row with linkId X. I would like to remove it but i am unsure how. In code i could just use a foreach from 0 to n and remove any found rows with a greater (or !=) id but thats in code. Is there a less difficult way of doing it using sqlite?
Assuming the table's name is tableName and there is a primary key field named id, the following sql would do it. I think the following SQL query is general enough and should be able to be executed under any database engine.
delete from tableName
where id not in (
select min(id) from tableName
group by linkId
)