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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in SQL Stored procedure. HELP!!!!!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi

I'm returning a string say STR1 from a table in a stored procedure

@STR1='AFG','ALB','IND'

when I query another table with IN clause. SQL looks like

SELECT * FROM DATA where IND0 in (@STR1)

It doesn't return anything. It works when the STR1 is just 'AFG'.

Is it a limitation?. or do I have to do differently.

Thanks

Sathya


 
Thank your very much for the immediate reply.

I tried it. But still it's not returning any records

Once again thank you very much for the tip.

Sathya
 

You CANNOT use a variable in the IN clause directly. You will need to create a SQL statement dynamically and then EXECUTE it.

Declare @sql nvarchar(2000)

Set @sql='SELECT * FROM DATA where IND0 IN (' + @STR1 + ')'
Exec @sql Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
Is there is way to execute a prepared SQL string in a stored procedure.

something like this.

@SQL = "SELECT * FROM DATA WHERE IND0 in (" + STR1 + ")"
EXEC SQL

Thanks

Sathya
 
I tried it. It's giving invalid stored procedure 'SELECT * FROM DATA"

Thanks

Sathya
 

Paul,

Thanks. I mistyped the Exec line. Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top