Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 problem?

Author  Topic 

sweet_777
Starting Member

16 Posts

Posted - 2010-10-07 : 02:16:34
Hi all,

I am passing concatenated column values as input parameter to the stored procedure.

concatenated column contains suppose 5 columns, that 5 columns contains null values, empty values, values.

i writing sp like this:


ALTER proc SP_DisplayEmail
(
@value varchar(1000),
@siteid int
)
as

DECLARE @Query varchar (1000)
begin

SET @Query = 'select ' + @value + ' from emp where siteid= ' + CONVERT (varchar (10),@siteid)
PRINT(@Query)
EXEC(@Query)

end

but i am getting null value.

how to check null value and how to written value .

regards
rama

Thanks & Regards
Sweet_77

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-07 : 04:49:50
Any value concatenated with null results in null value.

You need to check whether value is null or not using ISNULL(@variabletocheck,'substitute value or empty value')
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-07 : 04:53:18
Read this:
http://www.sommarskog.se/dynamic_sql.html

If you take the time to read that link and understand it you'll probably want to rethink your design.

Also -- where are you getting these parameters?

if they come from any front end input then this isn't safe. You are leaving yourself wide open to sql injection attack.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -