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 |
|
Deon Smit
Starting Member
47 Posts |
Posted - 2008-07-09 : 04:21:11
|
| Hi I am trying to use a variable. I have gotSelect distinct(wavekey), orderkey from pickdetailWhere orderkey in ( declare CUST string := &CUST1; begin Select distinct(A.orderkey) from orderdetail Ajoin orders Bon A.ORDERKEY = B.ORDERKEYwhere (B.consigneekey = CUST and B.RFIDSSCCLABELNAME = '1') or (B.consigneekey = CUST and B.RFIDGTINLABELNAME='1')end;)It prompt me for it but it doesn't work.? How can I use variable even without promting.Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-09 : 05:14:04
|
| This doesnt seem to be SQL Server code. Which db are you using? |
 |
|
|
Deon Smit
Starting Member
47 Posts |
Posted - 2008-07-10 : 03:24:08
|
| Oracle But I need to do the same type of thing on SQL 2000 aswell. Can you help me with variables in SQL? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-10 : 03:35:59
|
[code]SELECT DISTINCT(wavekey), orderkey FROM pickdetailWHERE orderkey IN ( DECLARE CUST string := &CUST1; BEGIN SELECT DISTINCT(A.orderkey) FROM orderdetail A JOIN orders B ON A.ORDERKEY = B.ORDERKEY WHERE ( B.consigneekey = CUST AND B.RFIDSSCCLABELNAME = '1' ) OR ( B.consigneekey = CUST AND B.RFIDGTINLABELNAME = '1' )END)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-10 : 04:13:12
|
| [code]DECLARE @CUST varchar(100)--variable to hold valueSET @CUST=yourvalue--assigning value to variableSelect distinct wavekey, orderkey from pickdetailWhere orderkey in ( Select distinct(A.orderkey) from orderdetail Ajoin orders Bon A.ORDERKEY = B.ORDERKEYwhere (B.consigneekey = @CUST and (B.RFIDSSCCLABELNAME = '1' or B.RFIDGTINLABELNAME='1'))[/code]you could even wrap this code in a stored procedure and make @CUST variable as a parameter and execute it with values you want. |
 |
|
|
Deon Smit
Starting Member
47 Posts |
Posted - 2008-07-10 : 10:34:53
|
| THanks everyone... |
 |
|
|
|
|
|