| Author |
Topic |
|
kiri
Starting Member
38 Posts |
Posted - 2008-02-13 : 15:17:49
|
| select len(sub) from tution where subject='maths' and subno=0 select len(sub) from tution where subject='maths' and subno=1it gives me44405210and281932it gives me error like Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.when i m using in my procdeclare @a int, @b intset @a = (select len(sub) from tution where subject='maths' and subno=0)set @b = (select len(sub) from tution where subject='maths' and subno=1) SELECT distinctsubno, sub = case when subno = 0 then sub when subno= 1 then subfrom tutioncan anybody help me where i have to use @a and @b to get correct results |
|
|
talleyrand
Starting Member
35 Posts |
Posted - 2008-02-13 : 18:10:41
|
| When you run the first two queries as is, it retuns multiple rows of data. In your proc, you are attempting to stick multiple values into a pair of variables. A variable can only hold one value at a time so what value should @a hold? 4, 4, 4, 0, 5, 2, or 10? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-14 : 04:20:33
|
| Do you want csv values?MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-14 : 04:42:14
|
| You need to specify what you want to do out of these values and whether you are interested in all value at a time. then we can suggest what you need to do. Can you please post your scenario? |
 |
|
|
kiri
Starting Member
38 Posts |
Posted - 2008-02-14 : 14:14:43
|
quote: Originally posted by madhivanan Do you want csv values?MadhivananFailing to plan is Planning to fail
yes, i want csv values..can u tell me how can i get that.thanks. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
talleyrand
Starting Member
35 Posts |
Posted - 2008-02-14 : 14:35:12
|
| If you want CSV values, then you will also need to change out your data type from int to some other data type, perhaps a character.declare @a int, @b int^^^^declare @a varchar(255), @b varchar(255) |
 |
|
|
kiri
Starting Member
38 Posts |
Posted - 2008-02-14 : 14:53:06
|
| thanks for ur reply..Peso and talleyrandi change my datatype..but i can't understand how to use this in my query.declare @a varchar(255), @b varchar(255)set @a = (select len(sub) from tution where subject='maths' and subno=0)set @b = (select len(sub) from tution where subject='maths' and subno=1)SELECT distinctsubno, sub = case when subno = 0 then subwhen subno= 1 then subfrom tution-----------------------------------------------------------------SELECT DISTINCT s1.subno, STUFF((SELECT DISTINCT TOP 100 PERCENT ',' + s2.sub FROM @a AS s2 WHERE s2.subno = s1.subno ORDER BY ',' + s2.sub FOR XML PATH('')), 1, 1, '') AS CODESFROM @a AS s1ORDER BY s1.subnoit gives me error:Msg 1087, Level 15, State 2, Line 5Must declare the table variable "@a". |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-15 : 02:13:11
|
| ReplaceFROM @a AS s1toFROM your_table AS s1MadhivananFailing to plan is Planning to fail |
 |
|
|
|