SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 problem?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sweet_777
Starting Member

16 Posts

Posted - 10/07/2010 :  02:16:34  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1182 Posts

Posted - 10/07/2010 :  04:49:50  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3451 Posts

Posted - 10/07/2010 :  04:53:18  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000