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 |
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-16 : 09:01:41
|
| Lets play spot the error! Can anyone see a syntax error in this? (FromDates and StartDates are for your benefits before any smart so and so comments on them)Set Transaction Isolation Level Read UncommittedDeclare @StartDate as DateTimeDeclare @EndDate as DateTimeDeclare @FromDate as DateTimeDeclare @ToDate as DateTimeSet @StartDate = <%FromDate|StartDate%>Set @EndDate = <%ToDate|EndDate%>Set @FromDate = dbo.fUniversalTime(@StartDate)Set @ToDate = dbo.fUniversalTime(@EndDate)Declare @ChilternVale as VarCharSelect Count(*), Case When (pg.Name like '%(040079)' or pg.Name like '%(040072)' or pg.Name like 'Intrahealth%' orpg.Name like '%(040066)' orpg.Name like '%(040030)' orpg.Name like '%(040047)' orpg.Name like '%(040009)' orpg.Name like '%(040003)' orpg.Name like '%(040063)' orpg.Name like '%(040077)' )End as @ChilternValeFrom [case] cJoin ProviderGroup pg on pg.ProviderGroupRef = c.ProviderGroupRefWhere c.ActiveDate between @FromDate and @ToDate and c.Cancelled = 0 and c.TestCall = 0Group By @ChilternValeI would use a temporary table for everything ever |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-09-16 : 09:08:07
|
| Set @StartDate = <%FromDate|StartDate%>Set @EndDate = <%ToDate|EndDate%>What is that? I've never seen that syntax before.JimEveryday I learn something that somebody else already knew |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2009-09-16 : 09:40:53
|
| Is that SQL???Well if it is then I can spot that all your case statement is messed up & also the "then" keyword missing in the case statement.PBUH |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-16 : 09:53:51
|
| Set @StartDate = <%FromDate|StartDate%>Set @EndDate = <%ToDate|EndDate%>That sets date filters in the 3rd party software I am using for when users run the report so they can easily select a date range.Cheers Idera, I knew it would be a stupid mistake. xDWhat is wrong with my case statement?case when ... then ... else ... end as ...?? I newbed it up on hereI would use a temporary table for everything ever |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2009-09-16 : 10:01:16
|
| First of all u can cannot use a variable in the group by clause the way u did it hereGroup By @ChilternValeTry this oneSelect Count(*),@ChilternVale=Case When pg.Name like '%(040079)' or pg.Name like '%(040072)' or pg.Name like 'Intrahealth%' orpg.Name like '%(040066)' orpg.Name like '%(040030)' orpg.Name like '%(040047)' orpg.Name like '%(040009)' orpg.Name like '%(040003)' orpg.Name like '%(040063)' orpg.Name like '%(040077)' then 'SOMETHING' ELSE 'NOTHING'End From [case] cJoin ProviderGroup pg on pg.ProviderGroupRef = c.ProviderGroupRefWhere c.ActiveDate between @FromDate and @ToDate and c.Cancelled = 0 and c.TestCall = 0Group By pg.NamePBUH |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-16 : 12:13:22
|
| cheers bossI would use a temporary table for everything ever |
 |
|
|
|
|
|