Author |
Topic |
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2010-03-03 : 04:55:41
|
SUM(CASE WHEN @days <= Convert(Int,(col1 from table1 where Name='AA') THEN 1 ELSE 0 END) as TestAbove query generates error'Incorrect syntax near the keyword 'from'.'Anyone tell me where it is wrong ??? Tks. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-03 : 04:57:49
|
The shown statement is part of a query and we need to see the query. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-03-03 : 04:59:23
|
quote: Originally posted by kwikwisi SUM(CASE WHEN @days <= Convert(Int,(col1 from table1 where Name='AA') THEN 1 ELSE 0 END) as TestAbove query generates error'Incorrect syntax near the keyword 'from'.'Anyone tell me where it is wrong ??? Tks.
u cant use the from clause therecan u explain the requirement briefly. |
|
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2010-03-03 : 05:02:26
|
select @days=dbo.TestFunction(), SUM(CASE WHEN @days <= Convert(Int,(col1 from table1 where Name='AA') THEN 1 ELSE 0 END) as Test,...,...from TblWhere Tbl.testcol = '0', ...,..quote: Originally posted by webfred The shown statement is part of a query and we need to see the query. No, you're never too old to Yak'n'Roll if you're too young to die.
|
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-03 : 05:08:43
|
select dbo.TestFunction(), SUM(CASE WHEN @days <= Convert(Int,col1) and Name='AA' THEN 1 ELSE 0 END) as Test,...,...from TblWhere Tbl.testcol = '0', ...,..MadhivananFailing to plan is Planning to fail |
|
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2010-03-03 : 19:32:38
|
Col1 and Name should come from another table.tks.quote: Originally posted by madhivanan select dbo.TestFunction(), SUM(CASE WHEN @days <= Convert(Int,col1) and Name='AA' THEN 1 ELSE 0 END) as Test,...,...from TblWhere Tbl.testcol = '0', ...,..MadhivananFailing to plan is Planning to fail
|
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-04 : 01:05:20
|
quote: Originally posted by kwikwisi Col1 and Name should come from another table.tks.quote: Originally posted by madhivanan select dbo.TestFunction(), SUM(CASE WHEN @days <= Convert(Int,col1) and Name='AA' THEN 1 ELSE 0 END) as Test,...,...from TblWhere Tbl.testcol = '0', ...,..MadhivananFailing to plan is Planning to fail
Join that table and use that column inside SUMMadhivananFailing to plan is Planning to fail |
|
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2010-03-04 : 06:07:16
|
Just want to compare @days with OthreTable.Column in SUM .Eg.SUM(CASE WHEN @days <= 100 THEN 1 ELSE 0 END) AS YAbove, I dont want to hardcode as 100. It should come from another table.I think cannot use join coz there is no relation bet 2 tables. Tks. quote: Originally posted by madhivanan
quote: Originally posted by kwikwisi Col1 and Name should come from another table.tks.quote: Originally posted by madhivanan select dbo.TestFunction(), SUM(CASE WHEN @days <= Convert(Int,col1) and Name='AA' THEN 1 ELSE 0 END) as Test,...,...from TblWhere Tbl.testcol = '0', ...,..MadhivananFailing to plan is Planning to fail
Join that table and use that column inside SUMMadhivananFailing to plan is Planning to fail
|
|
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2010-03-04 : 19:05:59
|
Can pls anyone tell me how to do it ? |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-05 : 01:55:03
|
quote: Originally posted by kwikwisi Can pls anyone tell me how to do it ?
Could you please execute this and see,this is what u required.iam a beginner..declare @table1 table( col int, name varchar(5))insert into @table1 values (1,'test') declare @col int,@name varchar(5) select @col=col,@name=name from @table1print @colprint @namethen use this params at when u summing up..quote: Just want to compare @days with OthreTable.Column in SUM .Eg.SUM(CASE WHEN @days <= 100 THEN 1 ELSE 0 END) AS Y
SUM(CASE WHEN @days <= @col THEN 1 ELSE 0 END) AS Y |
|
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2010-03-05 : 02:20:13
|
Thanks.quote: Originally posted by haroon2k9
quote: Originally posted by kwikwisi Can pls anyone tell me how to do it ?
Could you please execute this and see,this is what u required.iam a beginner..declare @table1 table( col int, name varchar(5))insert into @table1 values (1,'test') declare @col int,@name varchar(5) select @col=col,@name=name from @table1print @colprint @namethen use this params at when u summing up..quote: Just want to compare @days with OthreTable.Column in SUM .Eg.SUM(CASE WHEN @days <= 100 THEN 1 ELSE 0 END) AS Y
SUM(CASE WHEN @days <= @col THEN 1 ELSE 0 END) AS Y |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-05 : 09:57:26
|
quote: Originally posted by kwikwisi Just want to compare @days with OthreTable.Column in SUM .Eg.SUM(CASE WHEN @days <= 100 THEN 1 ELSE 0 END) AS YAbove, I dont want to hardcode as 100. It should come from another table.I think cannot use join coz there is no relation bet 2 tables. Tks. quote: Originally posted by madhivanan
quote: Originally posted by kwikwisi Col1 and Name should come from another table.tks.quote: Originally posted by madhivanan select dbo.TestFunction(), SUM(CASE WHEN @days <= Convert(Int,col1) and Name='AA' THEN 1 ELSE 0 END) as Test,...,...from TblWhere Tbl.testcol = '0', ...,..MadhivananFailing to plan is Planning to fail
Join that table and use that column inside SUMMadhivananFailing to plan is Planning to fail
if they have no relationship then whats the meanng of using it in sum() ?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|