Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

828 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