| Author |
Topic  |
|
|
kwikwisi
Constraint Violating Yak Guru
278 Posts |
Posted - 03/03/2010 : 04:55:41
|
SUM(CASE WHEN @days <= Convert(Int,(col1 from table1 where Name='AA') THEN 1 ELSE 0 END) as Test
Above query generates error 'Incorrect syntax near the keyword 'from'.'
Anyone tell me where it is wrong ??? Tks. |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8515 Posts |
Posted - 03/03/2010 : 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
Flowing Fount of Yak Knowledge
India
1693 Posts |
Posted - 03/03/2010 : 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 Test
Above query generates error 'Incorrect syntax near the keyword 'from'.'
Anyone tell me where it is wrong ??? Tks.
u cant use the from clause there can u explain the requirement briefly. |
 |
|
|
kwikwisi
Constraint Violating Yak Guru
278 Posts |
Posted - 03/03/2010 : 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 Tbl Where 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
India
22461 Posts |
Posted - 03/03/2010 : 05:08:43
|
select dbo.TestFunction() , SUM(CASE WHEN @days <= Convert(Int,col1) and Name='AA' THEN 1 ELSE 0 END) as Test ,... ,... from Tbl Where Tbl.testcol = '0', ...,..
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
kwikwisi
Constraint Violating Yak Guru
278 Posts |
Posted - 03/03/2010 : 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 Tbl Where Tbl.testcol = '0', ...,..
Madhivanan
Failing to plan is Planning to fail
|
Edited by - kwikwisi on 03/03/2010 20:20:50 |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 03/04/2010 : 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 Tbl Where Tbl.testcol = '0', ...,..
Madhivanan
Failing to plan is Planning to fail
Join that table and use that column inside SUM
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
kwikwisi
Constraint Violating Yak Guru
278 Posts |
Posted - 03/04/2010 : 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 Y
Above, 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 Tbl Where Tbl.testcol = '0', ...,..
Madhivanan
Failing to plan is Planning to fail
Join that table and use that column inside SUM
Madhivanan
Failing to plan is Planning to fail
|
 |
|
|
kwikwisi
Constraint Violating Yak Guru
278 Posts |
Posted - 03/04/2010 : 19:05:59
|
| Can pls anyone tell me how to do it ? |
Edited by - kwikwisi on 03/05/2010 01:36:22 |
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 03/05/2010 : 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 @table1 print @col print @name
then 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 |
Edited by - haroon2k9 on 03/05/2010 01:58:29 |
 |
|
|
kwikwisi
Constraint Violating Yak Guru
278 Posts |
Posted - 03/05/2010 : 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 @table1 print @col print @name
then 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
India
47189 Posts |
Posted - 03/05/2010 : 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 Y
Above, 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 Tbl Where Tbl.testcol = '0', ...,..
Madhivanan
Failing to plan is Planning to fail
Join that table and use that column inside SUM
Madhivanan
Failing to plan is Planning to fail
if they have no relationship then whats the meanng of using it in sum() ?
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|