Friday, February 10, 2012

Check Table Values in the Store Procedure...

HI

I have a problem related Store Procedure, that i am trying to extact a value from Database (Like FirstName,LastName,Email Address) through Store Procedure and Display it in the DropDownList(Like: FirstName LastName ,(xyz@.xyz.com)) , and this is working correctly.

Now i try to check the value at the same time if it is NULL value in the Database then pass EmptyString to the DropDownList Like ("" "" ,(xyz@.xyz.com))\

how i can do that in the store procedure.

Comments will be appreciated.

Use the IsNull function.

|||

You could save the results to a temp table in the stored procedure then do an update replacing all nulls with "" then just return the contents of the temp table. e.g

CREATE TABLE #tmpTable
(
field1as NVARCHAR(200),
field2as integer
)

INSERT INTO #tmpTable (field1,Field2)
SELECT * FROM SelectionTable

UPDATE #tmpTable SET field1 ="" WHERE field1 isnull

SELECT * FROM #TmpTable

DROP #tmpTable

|||

You can use the Isnull function directly in your select query like this:

select firstName , lastName ,IsNull ( email ,'' )as emailfrom <table Name>

This way you are rest assured that for whichever row the email is null, it will automatically be converted to '' ( blank string ). You can write anything like 'Not Available' in the replacement part of the isnull function.

Hope this will help.

No comments:

Post a Comment