sql to linq.
-
Hi guys, I'm having real trouble converting this SQL statement into linq. I've been converting some code samples but have got stuck with this last one. Any Ideas? Your help would be truly appreciated!
"SELECT AdId,Count(*) As Impressions
FROM AdStats
WHERE Type=0
GROUP BY AdId
ORDER BY Impressions DESC"Impressions is one of two databound fields in my gridview, (AdId is the other). What I need is a single result that I can use as the datasource for my gridview. I can see what the code is doing, I just can't replicate it. Thanks in advance.
JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************
-
Hi guys, I'm having real trouble converting this SQL statement into linq. I've been converting some code samples but have got stuck with this last one. Any Ideas? Your help would be truly appreciated!
"SELECT AdId,Count(*) As Impressions
FROM AdStats
WHERE Type=0
GROUP BY AdId
ORDER BY Impressions DESC"Impressions is one of two databound fields in my gridview, (AdId is the other). What I need is a single result that I can use as the datasource for my gridview. I can see what the code is doing, I just can't replicate it. Thanks in advance.
JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************
Jim, one thing that stumps me with this query is the selecting of Count(*) and ordering by that. Count(*) will count the number of results returned from the AdStats table, but ordering by Count(*)? I don't understand that. (Mind you, I'm not a SQL expert by any means, so pardon me if this is a dumb question.)
-
Jim, one thing that stumps me with this query is the selecting of Count(*) and ordering by that. Count(*) will count the number of results returned from the AdStats table, but ordering by Count(*)? I don't understand that. (Mind you, I'm not a SQL expert by any means, so pardon me if this is a dumb question.)
You'd normally order by a count if you want your results ordered by items like popularity, etc.
Deja View - the feeling that you've seen this post before.
-
Hi guys, I'm having real trouble converting this SQL statement into linq. I've been converting some code samples but have got stuck with this last one. Any Ideas? Your help would be truly appreciated!
"SELECT AdId,Count(*) As Impressions
FROM AdStats
WHERE Type=0
GROUP BY AdId
ORDER BY Impressions DESC"Impressions is one of two databound fields in my gridview, (AdId is the other). What I need is a single result that I can use as the datasource for my gridview. I can see what the code is doing, I just can't replicate it. Thanks in advance.
JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************
SQL doesn't recognise aliases in places, so e.g.
"SELECT AdId,Count(*) As Impressions
FROM AdStats
WHERE Type=0
GROUP BY AdId
HAVING Impressions > 10
ORDER BY Impressions DESC"Will not work with the alias in the
HAVING
clause. Maybe LINQ doesn't like the alias in yourORDER BY Impressions DESC
, in favour ofORDER BY Count(*) DESC
-
Hi guys, I'm having real trouble converting this SQL statement into linq. I've been converting some code samples but have got stuck with this last one. Any Ideas? Your help would be truly appreciated!
"SELECT AdId,Count(*) As Impressions
FROM AdStats
WHERE Type=0
GROUP BY AdId
ORDER BY Impressions DESC"Impressions is one of two databound fields in my gridview, (AdId is the other). What I need is a single result that I can use as the datasource for my gridview. I can see what the code is doing, I just can't replicate it. Thanks in advance.
JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************
Thanks for your replies guys. I had a wee read and messed around. I think I have it cracked but i need to test it yet. What do you reckon of this? Makes sense?
Dim result = From a In dc.OFG_AdStats _
Group By AdId = a.AdId _
Into Impressions = Count(a.Type = 0) _
Order By Impressions Descending _
Select AdId, ImpressionsThanks
JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************