Re: set a select statement stored in a table in a variable
From: Hari Prasad (hari_prasad_k_at_hotmail.com)
Date: 07/22/04
- Next message: martin: "Re: What is NOWAIT for? What is the InfoMessage Event for?"
- Previous message: karditsi_at_csd.uoc.gr: "set a select statement stored in a table in a variable"
- In reply to: karditsi_at_csd.uoc.gr: "set a select statement stored in a table in a variable"
- Next in thread: (no email): "Re: set a select statement stored in a table in a variable"
- Reply: (no email): "Re: set a select statement stored in a table in a variable"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 22 Jul 2004 15:51:39 +0530
Hi,
You do not require a dynamic sql statement to use a variable after = clause.
You script should be some thing like
declare @patcode varchar(10)
set @patcode='hari123'
SELECT PATLAST FROM PAT1FILE WHERE PATCODE like @PATCODE
You need to have dynamic sql only if you construct the statment with
differnt table names or column names.
Thanks
Hari
MCDBA
"Korina" <karditsi@csd.uoc.gr> wrote in message
news:#bR0FR9bEHA.3012@tk2msftngp13.phx.gbl...
> Hello,
>
> I have a table containing select statements
> in each of it's columns.
>
> Inside a stored procedure I want to set
> the value of the column i.e the statement
> into a variable and then execute it using
> the command
> EXEC sp_executesql @QUERY
>
> If I print the value of the variable containing
> the query I get the statement
> 'SELECT PATLAST FROM PAT1FILE WHERE PATCODE = "' +@PATCODE+'"'
>
> but when i execute the store procedure
> I get the error
> Incorrect syntax near 'SELECT PATLAST FROM PAT1FILE WHERE PATCODE = "'.
>
> Does anynone have any idea?
>
> Thanks in advance
> Korina
>
>
> **********************************************************************
> Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
> Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
- Next message: martin: "Re: What is NOWAIT for? What is the InfoMessage Event for?"
- Previous message: karditsi_at_csd.uoc.gr: "set a select statement stored in a table in a variable"
- In reply to: karditsi_at_csd.uoc.gr: "set a select statement stored in a table in a variable"
- Next in thread: (no email): "Re: set a select statement stored in a table in a variable"
- Reply: (no email): "Re: set a select statement stored in a table in a variable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|