Solved

T- SQL Check for String.Empty or Nulls in a Passed Parameter

Posted on 2007-11-29
4
21,520 Views
Last Modified: 2012-08-14
I have a stored procedure that receives 20 different parameters as fully built Insert queries...The potential exists though that some of those parameters may be passed to the stored-procedure as empty or nulls.  I need to check to make sure that it is not empty or nulls before I actually EXEC the @SQL.  Can someone please let me know how to do that.  A small portion of the Stored Procedure code is attached.  I have arrows pointing to where I need to check the parameter.  Please show me the right way of doing that.   Help!  msyed1.

 
CREATE PROCEDURE dbo.USP_InsertNewConnectionTables

@CONNInsertSQL varchar(6000) 
 

 

AS
 

BEGIN TRANSACTION

Set Nocount On

Declare @SQL varchar (6000)
 
 

Select @SQL = @CONNInsertSQL

If @SQL <>     String.Empty or NULLS     <<<===================

Begin

  EXEC(@SQL)

  IF @@ERROR <> 0

   BEGIN

    ROLLBACK TRANSACTION

    RETURN (214)

   END

END
 
 
 

COMMIT TRANSACTION

Return 55

GO

Open in new window

0
Comment
Question by:msyed1
  • 2
4 Comments
 
LVL 15

Expert Comment

by:danrosenthal
ID: 20376279
How about:
If @SQL IS NOT NULL
0
 
LVL 25

Accepted Solution

by:
imitchie earned 125 total points
ID: 20376311
check for both '' and NULL

If ISNULL(@SQL, '') <> ''
0
 

Author Comment

by:msyed1
ID: 20376341
imitchie: will this check for both NULLS and an empty string.  I need to check for both....
0
 
LVL 15

Assisted Solution

by:danrosenthal
danrosenthal earned 125 total points
ID: 20376485
Either of these should work:

If @SQL IS NOT NULL OR @SQL <> ''

If ISNULL(@SQL, '') <> ''

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Syntax join to include values from first table 3 26
datetime in sql 6 23
TSQL DateADD update Question 4 25
SQL 2008 R2 calc date formula 3 18
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now