| Author |
Topic |
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-14 : 22:33:51
|
| i try to create a store pro, something likeDECLARE @aaa char(13)DECLARE CURSORA CURSOR FORSELECT column1FROM TABLE_1WHERE @aaa=(SELECT min(@aaa)FROM TABLE_1...PRINT CAST(@aaa as char(15))the result is not the result i wan...how come??can anyone please help me...millionx thx...bless you...muaks |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-14 : 22:56:31
|
| help...quite urgent... |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-05-14 : 23:07:20
|
Please clearify your question. Also your query does not look accurate. Post the table structure, sample data and desired results. Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-14 : 23:08:06
|
| maybe i was not clear....the result of the cursor will not show the minimun but it show the 1st row of the table |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-14 : 23:08:21
|
You have to tell us more what are you trying to do before we can help you.Please provide your table's DDL, sample data and the expected result KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-14 : 23:12:32
|
| TABLE_1column1| A | B | C |A | 0 | 2 | 4 |B | 2 | 0 | 5 |C | 4 | 5 | 0 |CREARE PROCEDURE testing (@getA CHAR(1))ASDECLARE @resultA VARCHAR(30)DECLARE CURSORA CURSOR FORSELECT column1FROM TABLE_1WHERE @getA=(SELECT min(@getA)FROM TABLE_1 WHERE @get <> 0)BEGINOPEN CURSORAFETCH NEXT FROM CURSORAINTO @resultAPRINT CAST(@resultA as char(30))CLOSE CURSORADEALLOCATE CURSORAEND |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-14 : 23:14:04
|
| result will be2 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-14 : 23:23:03
|
not very sure what is the purpose of your cursor . . try thisselect *from TABLE_1where A = (select min(A) from TABLE_1 WHERE A <> 0) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-14 : 23:25:00
|
| the purpose of my cursor is that when the userEXEC testing 'B'it will show the result 2EXEC testing 'C'it will show the result 4 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-14 : 23:26:54
|
how many of such columns you need to "test" ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-14 : 23:39:08
|
| erm....around 20... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-14 : 23:44:17
|
[code]CREATE PROCEDURE testing (@getA CHAR(1))ASBEGIN DECLARE @sql nvarchar(1000) SELECT @sql = 'select column1 from TABLE_1 where ' + @getA + ' = (select min(' + @getA + ') from TABLE_1 WHERE ' + @getA + ' <> 0)' exec (@sql)END[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-14 : 23:58:57
|
| >"< it prompt out 'variable assignment is not allowed in a cursor declaration' |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-15 : 00:07:48
|
quote: Originally posted by waterduck >"< it prompt out 'variable assignment is not allowed in a cursor declaration'
I don't use cursor at all in the Stored Procedure that i posted. Just copy and paste the code in your Query Window and run. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-05-15 : 00:20:49
|
| OMG thx alot...really really thx...muaks ^^ |
 |
|
|
|