November 5, 2008 at 6:41 am
November 5, 2008 at 6:49 am
You are right .
But query mentioned below works.
select * from tm_temp_empmastall where employeeid='483503'
November 5, 2008 at 6:53 am
It looks like you are missing out a step in your query, you are inserting a value into a variable then selecting from a table. Where is the step to insert this value into the table?
November 5, 2008 at 7:03 am
it doesnt work because you are putting three quotes around your variable (''') you do not need to do this, surround it in single quotes (') and since the variable is the same datatype as your column (I assume) you do not need to include any quotes in the variable value
set @ab='483503'
select * from tm_temp_empmastall where employeeid=@ab
November 5, 2008 at 7:10 am
pramod.chauhan (11/5/2008)
firstly set @ab='''483503''' is creating a variable who value is '483503'
Why do you want to store that extra pair of single quotes as part of the variable?
The value you want to store as a variable is 483503 as an int, or 483503 as a character type.
Try this:
DECLARE @ab VARCHAR (100)
SET @ab = '483503'
SELECT CAST(@ab AS INT)
SET @ab = '''483503'''
SELECT CAST(@ab AS INT)
Cheers
ChrisM
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 5, 2008 at 8:01 am
thanks for qiick reply
@ab will have the all employeeid selected in reporting service interface.
and then i want to pass the @ab to stored procedure to give employee details.
there would be multiple employeeids in @ab
@ab='483503,483504'
and then
select * from tm_temp_empmastall where employeeid in (@ab)
November 5, 2008 at 8:09 am
pramod.chauhan (11/5/2008)
thanks for qiick reply@ab will have the all employeeid selected in reporting service interface.
and then i want to pass the @ab to stored procedure to give employee details.
there would be multiple employeeids in @ab
@ab='483503,483504'
and then
select * from tm_temp_empmastall where employeeid in (@ab)
You will need to resolve the contents of the variable for this to work. The two commonest ways are:
1. Resolve the list into a temp table or table variable
2. Use dynamic SQL, something like this:
SET @cSQL = 'select * from tm_temp_empmastall where employeeid in (' + @ab + ')'
Cheers
ChrisM
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 5, 2008 at 8:47 am
When i execute the following code.
declare @ab varchar (100)
declare @cSQL varchar (200)
set @ab='''483503'',''483504'''
print @ab
SET @cSQL = 'select * from tm_temp_empmastall where employeeid in (' + @ab + ')'
print @cSQL
exec @cSQL
I get the below mentioned error.
"Could not find stored procedure 'select * from tm_temp_empmastall
where employeeid in ('483503','483504')'."
November 5, 2008 at 8:50 am
Try this...
EXEC (@cSQL)
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 6, 2008 at 9:05 am
how can i do it without using dynamic sql
November 6, 2008 at 9:11 am
I can't think of a way unless the employeeid values are written to a table prior to calling the procedure. If that is the case, you can simply add a sub query following your IN clause that selects the desired values.
SELECT
*
FROM
tmpEmployee
WHERE
employeeid IN (SELECT employeeid FROM tmpValues)
November 6, 2008 at 9:17 am
if @db is int then you get the result.
Viewing 15 posts - 1 through 15 (of 17 total)
You must be logged in to reply to this topic. Login to reply