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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Variable help.

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 got

Select distinct(wavekey), orderkey from pickdetail
Where 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;)


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?
Go to Top of Page

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?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-10 : 03:35:59
[code]SELECT DISTINCT(wavekey), orderkey
FROM pickdetail
WHERE 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]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-10 : 04:13:12
[code]DECLARE @CUST varchar(100)--variable to hold value
SET @CUST=yourvalue--assigning value to variable

Select distinct wavekey, orderkey from pickdetail
Where orderkey in
(
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.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.
Go to Top of Page

Deon Smit
Starting Member

47 Posts

Posted - 2008-07-10 : 10:34:53
THanks everyone...
Go to Top of Page
   

- Advertisement -