Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

case statement for where clause

$
0
0

Hi Experts,

Exclude or include where clause based on parameter value,

CREATE TABLE #TEMP
(
	ID	CHAR(1)
)

INSERT INTO #TEMP VALUES ( '1' )
INSERT INTO #TEMP VALUES ( '2' )
INSERT INTO #TEMP VALUES ( '3' )

DECLARE	@ID	CHAR(1)
SET		@ID	=	''--'2'

SELECT	*
FROM	#TEMP
WHERE	1 = CASE WHEN LEN(@ID) <> 0 THEN @ID ELSE 1 END

DROP TABLE #TEMP

Any help?

Thanks

Kumar


Please do let us know your feedback. Thank You - KG, MCTS


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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