Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Append where clause in to SQL statement without IF..ELSE ?

$
0
0

Hi,

I have SQL Statement like this.

CREATE PROCEDURE [dbo].[GetRecords] @option AS BIT = NULL
AS
BEGIN
	IF @option = '1'
	BEGIN
		SELECT *
		FROM testTable
		WHERE column1 IS NOT NULL AND Column2 IS NOT NULL AND Column3 IS NOT NULL
	END
	ELSE
	BEGIN
		SELECT *
		FROM testTable
		WHERE column1 IS NOT NULL
	END
END

Please help me to write in to single statement with out IF... ELSE

Thank you.



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>