Solved

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

Posted on 2007-11-29
4
21,561 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

749 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