Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-07-21 : 09:38:41
|
| David writes "Im trying to get a count of rows returned by SQL statement, I am using Inner joins, but what ever I try seems not to work..help!string cmdStringSingle = "SELECT COUNT(*) FROM ((((([Db3] INNER JOIN Db2 ON [Db3].[Client no] = Db2.[Client no]) INNER JOIN db5 ON [Db3].Hid = db5.Hid) INNER JOIN [DB1] ON Db2.[ID] = [DB1].[ID]) INNER JOIN Db6 ON db5.HotelID = Db6.[Hotel Ref]) INNER JOIN db4 ON [Db3].StatusID = db4.StatusID)WHERE ( [DB1].active=false AND Db6.[Hname] = '" + strHname + "' AND [Db3].[Arrival Date]= " + startdate + " AND db4.Status=’active’) ORDER BY db4.StatusID, [DB1].[ID] ";always get the error:Syntax error (missing operator) in query expression 'COUNT(*)" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-07-21 : 09:42:41
|
| I guess you are doing this in an application. You should be able to get the count from the resultset.Otherwise"set nocount on select ... into #a from ..... select cnt, #a.* from #a, (select count(*) from #a) a"unless you are v2005 in which case you can use a CTE.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-21 : 11:29:29
|
| or use stored procedure and make use of @@RowcountQuerySelect @@RowcountMadhivananFailing to plan is Planning to fail |
 |
|
|
tonymorell10
Yak Posting Veteran
90 Posts |
Posted - 2006-07-21 : 11:57:46
|
[quote]Originally posted by AskSQLTeam David writes "Im trying to get a count of rows returned by SQL statement, I am using Inner joins, but what ever I try seems not to work..help!Try this:string cmdStringSingle = "SELECT COUNT(*) FROM ((((((SELECT [Db3].[Client no] FROM [Db3] INNER JOIN Db2 ON [Db3].[Client no] = Db2.[Client no]) INNER JOIN db5 ON [Db3].Hid = db5.Hid) INNER JOIN [DB1] ON Db2.[ID] = [DB1].[ID]) INNER JOIN Db6 ON db5.HotelID = Db6.[Hotel Ref]) INNER JOIN db4 ON [Db3].StatusID = db4.StatusID)WHERE ( [DB1].active=false AND Db6.[Hname] = '" + strHname + "' AND [Db3].[Arrival Date]= " + startdate + " AND db4.Status=’active’) ORDER BY db4.StatusID, [DB1].[ID]) AS T"; |
 |
|
|
|
|
|