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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 What is wrong with this SQL statement???

Author  Topic 

SimonGough
Starting Member

23 Posts

Posted - 2002-01-11 : 06:46:03
select jobID, transportjobnumber from transport_job_numbers
where jobID = 1
select @transjobnum = transportjobnumber


This SQL is from a transaction in an insert stored procedure. I need to grab this number and then set it to the @transjobnum variable but I am getting an 'Invalid column name' error for 'transportjobnumber'

there are no spelling mistakes or anything so I can't figure what is wrong

any idea's???

Simon

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-01-11 : 06:57:41
Hi Simon

That is running as two separarate statements.
By the time the second select runs, it has no idea what transportjobnumber is. Also you can not do variable assigning in the same batch, so you would have to do this



select jobID, transportjobnumber,
from transport_job_numbers
where jobID = 1

Select @transjobnum = transportjobnumber
from transport_job_numbers
where jobID = 1



Hope that helps

Damian
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-01-11 : 17:25:49
quote:
Also you can not do variable assigning in the same batch...


OK, Merkin, why do you say this? Is it because Simon mentioned that this is in an insert stored procedure? I don't see any INSERT syntax here, so I guess we're assuming that the syntax being used is

INSERT INTO.... SELECT jobID, trans...

In that case, I agree. However, if this select is separate from the INSERT statement (even though it's in the same stored procedure), then it seems to me you could do the assigning in the one statement.

--------------------------------
There's a new General in town...

Edited by - AjarnMark on 01/11/2002 17:26:21
Go to Top of Page
   

- Advertisement -