Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 SELECT Multiple Criterias IF NOT NULL

Author  Topic 

cortpcl
Starting Member

4 Posts

Posted - 2014-09-02 : 04:51:02
HI all,

I have a dataset where i want to select the records that matches my input values. But i only want to try macthing a field in my dataset aginst the input value, if the dataset value is not NULL.

I allways submit all 4 input values.
@Tyreid, @CarId,@RegionId,@CarAgeGroup


So for the first record in the dataset i get a succesfull output if my input values matches RegionId and CarAgeGroup.

I cant figure out how to create the SQl script for this SELECT?

My dataset
TyreId CarId RegionId CarAgeGroup
NULL NULL 1084 2
65 35 1084 1
5 35 1084 1
NULL 41 1085 NULL
120 NULL NULL NULL
NULL NULL 1084 2
65 NULL 1084 NULL

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-09-02 : 15:50:41
Given the sample data you provided, what should the SELECT return?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -