March 16, 2009 at 3:00 pm
I am writing SP in SQL-Server select some rows from a table. Like
=======
Create Proc Test
@strIDs NVARCHAR(500)
as
SELECT * FROM [dbo].[test_table]
where Serial_No in (@strIDs )
=======
Column is of type bigint.
when i run thid proc like:
exec Test '1,3,4,6,7,8'..
I get this errir : 'Error converting data type nvarchar to bigint.'
but it runs fine with exec Test '1',
Note:Only one item in the list..
Any solution for the same ?
March 16, 2009 at 10:06 pm
"Teach a man to fish and..."
All of your questions are answered in the following two articles...
http://www.sqlservercentral.com/articles/TSQL/62867/
http://www.sqlservercentral.com/articles/T-SQL/63003/
--Jeff Moden
Change is inevitable... Change for the better is not.
March 17, 2009 at 6:47 am
Not nearly as elegant but might serve your purpose.
drop proc test
go
drop table test_table
go
create table dbo.test_table (Serial_No int)
go
insert into dbo.test_table values (1)
insert into dbo.test_table values (3)
insert into dbo.test_table values (5)
insert into dbo.test_table values (7)
insert into dbo.test_table values (9)
go
Create Proc Test
@strIDs NVARCHAR(500)
as
declare @sql varchar(255)
set @sql = 'SELECT * FROM [dbo].[test_table] where Serial_No in (' + @strIDs + ')'
exec (@sql)
go
exec Test '1,3,4,6,7,8'
go
_____________________________________________________________________
- Nate
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply