Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

into error

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi friends
create procedure myitem
@it int,@qty int, @price int
as
declare @m int
select item into @m from stock where item=@it
if @m is null
print 'message '

but it give errors say variable must be declare
what problem in it

thanks
m.a.khaleel
 

What exactly are you trying to do?

The SQL SELECT INTO statement creates a new table. If you want to create a new table, you must select into a table name. If this is what you want, then in SQL 2000 you must declare @m as a table variable. In earlier versions of SQL Server, you can't use a variable for a table name. You must use dynamic SQL.

In your posted statement, Select Item Into @m ..., you are SELECTing INTO an integer variable, @m. If you are trying to Assign a value to the variable @m then you should use the assignment operator =.

SELECT @m=col_name FROM stock WHERE item=@it

The T-SQL script that you posted is confusing. That's why I asked for more explanation of your intent.

Thanks, Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
I assume khaleel2001 is an Oracle guy in a SQL database. :) Oracle's INTO statement is for variables, not tables.

khaleel2001, listen to Terry, he is right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top