Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,
below is my storeprocedure will convert the binary data into bigint
SQL
ALTER proc

[dbo]. XXX (@Value nvarchar(4000),@returnValue BIGINT OUTPUT)
as
Begin
select @returnValue= convert(bigint,cast(@Value as binary))  from [dbo].[##Mytemp];

End

am passing col name as parameter but it is not giving output,when i replace that parameter with actualy colname of table i.e (example col4) is working
i nedd to pass column name as parameter is it possible?

any correction in the SP
Posted
Updated 1-Feb-12 19:00pm
v2

You can pass column name as parameter, in that case you have to execute the query dynamically:

example:
exec('select convert(bigint,cast(' + @Value + ' as binary)) from [dbo].[##Mytemp]');


This will give you the recordset and not the output parameter.

You can also look at the following link on using sp_executesql:

SQL
DECLARE @i INT, @sql NVARCHAR(512)
SET @sql = N'SELECT @i = COUNT(*) FROM ' + @dbname + '.INFORMATION_SCHEMA.TABLES'
EXEC sp_executesql @query = @sql, @params = N'@i INT OUTPUT', @i = @i OUTPUT



http://sqlserver2000.databases.aspfaq.com/how-do-i-get-the-result-of-dynamic-sql-into-a-variable.html[^]
 
Share this answer
 
v2
Comments
Rajesh Anuhya 2-Feb-12 1:19am    
Missing code tags added
--RA
pradeep manne 2-Feb-12 1:26am    
HI,
Thanks for the reply and the article
SQL
CREATE PROCEDURE dbo.countTables
    @dbname SYSNAME
AS
BEGIN
    DECLARE @i INT, @sql NVARCHAR(512)

    SET @sql = N'SELECT @i = COUNT(*) FROM '
        + @dbname + '.INFORMATION_SCHEMA.TABLES'

    EXEC sp_executesql
        @query = @sql,
        @params = N'@i INT OUTPUT',
        @i = @i OUTPUT

    PRINT @i
END
GO
 
Share this answer
 
Detailed explanation here
http://www.informit.com/articles/article.aspx?p=25288&seqNum=6[^]

Thanks
--RA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900