Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have stored procedure where select and filtering data. For example :

select CONVERT(nvarchar,[Date],120) , [FirstName] , [LastName]
FROM myDB
WHERE  (@Date IS NULL OR @Date = '' OR [Date] = @Date)
       (@FirstName IS NULL OR @FirstName  = '' OR [FirstName] = @FirstName)
       (@LastName IS NULL OR @LastName  = '' OR [LastName] = @LastName)

When i filtering by FirstName or/and LastName it works , but when I want filter by Data it dont work , I think there is convert problem maybe ? I exec like :

exec myProc '2013-02-03','',''
share|improve this question
"it dont work" - not very descriptive. also, that snippet won't compile... – Mitch Wheat 8 hours ago
1  
What is the header of the procedure? So we can see parameter datatypes and order. – Martin Smith 8 hours ago
try using date conversion method in where condition also.. It may work – SuganR 8 hours ago
thank you guys for answering , when I write date and then execute it doesnt take any parametrs from table – GeoVIP 8 hours ago

1 Answer

up vote 3 down vote accepted

Possible this be helpful for you -

SELECT 
      CONVERT(NVARCHAR,[Date],120) 
    , [FirstName] 
    , [LastName]
FROM myDB
WHERE ISNULL(@Date, [Date]) = [Date] --<--
    AND (ISNULL(@FirstName, '') = '' OR [FirstName] = @FirstName) 
    AND (ISNULL(@LastName, '') = '' OR [LastName] = @LastName)
share|improve this answer
1  
thank you for answering but with this code is same result. When write date and then execute it doesnt take any parametrs from table – GeoVIP 8 hours ago
thank you for answering I am begginer in sql server how do it ? – GeoVIP 8 hours ago
A small breadcrumb - Object Explorer -> <your db> -> Programmability -> Stored Procedures -> <your stored procedure (sp)> -> popup menu -> Script Stored Procedure AS -> CREATE – Devart 8 hours ago
thank you for help , i solve problem – GeoVIP 8 hours ago
You're welcome @GeoVIP. – Devart 8 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.