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 |
|
liptonIcedTea
Starting Member
26 Posts |
Posted - 2008-03-04 : 00:40:25
|
| Why couldn't they make SQL syntax error mistakes a little less vague.Anyway, I was wondering, is it possible to use a set in your case statement? CASE ( select distinct tbhtg.TrainingBlockHistoryTypeGroupingCd from tblTrainingBlockHistory tbh inner join tblTrainingBlockHistoryType tbht on tbh.TrainingBlockHistoryTypeCd = tbht.TrainingBlockHistoryTypeCd inner join tblTrainingBlockHistoryTypeGrouping tbhtg on tbht.TrainingBlockHistoryTypeGroupingCd = tbhtg.TrainingBlockHistoryTypeGroupingCd where (select dbo.fnTrainingBlockStatus( 1234, getdate())) = tbht.TrainingBlockHistoryTypeCd ) WHEN 'S' then (COUNT(DISTINCT TRD.TrainingBlockHistoryId) = COUNT(DISTINCT SWT.TrainingBlockHistoryId)) endThis is giving me an error on the WHEN statement. The error is "Incorrect syntax near '='" Have no idea how to fix this.But the select statement seems to work, and as far as I can tell, that is how you write a CASE statement.Also, this CASE statement is inside the HAVING clause - is that going to be a problem? |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2008-03-04 : 00:43:45
|
| U can not assign a value inside CASE statement, either u can try thisCOUNT(DISTINCT TRD.TrainingBlockHistoryId) = CASE(select distinct tbhtg.TrainingBlockHistoryTypeGroupingCdfrom tblTrainingBlockHistory tbhinner join tblTrainingBlockHistoryType tbht on tbh.TrainingBlockHistoryTypeCd = tbht.TrainingBlockHistoryTypeCdinner join tblTrainingBlockHistoryTypeGrouping tbhtg on tbht.TrainingBlockHistoryTypeGroupingCd = tbhtg.TrainingBlockHistoryTypeGroupingCdwhere (select dbo.fnTrainingBlockStatus( 1234, getdate())) = tbht.TrainingBlockHistoryTypeCd)WHEN 'S' then COUNT(DISTINCT SWT.TrainingBlockHistoryId) end |
 |
|
|
liptonIcedTea
Starting Member
26 Posts |
Posted - 2008-03-04 : 00:51:38
|
| I'm not trying to assign a value inside the CASE statementThis whole statement is wrapped inside a HAVING clause, I was basically, saying that if that select statement returns a certain value, then put the content of the THEN statement in the HAVING clause, am i going about this the wrong way? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-03-04 : 01:13:02
|
quote: Originally posted by liptonIcedTea am i going about this the wrong way?
Perhaps, but it's hard to know with the information that you've provided. Could you describe your problem in words plus show us a data sample?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
|
|
|
|
|