Solved

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

Posted on 2007-11-29
4
21,573 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

734 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