• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 38
  • Last Modified:

SQL Query

Hello,
I am writing a stored procedure with a query

IF NOT EXISTS( SELECT [Date],[Time],PickUpTime
                          FROM DIY WHERE( [Date] = CONVERT(NVARCHAR(20),@Date,112)  AND  [PickUpTime] = CONVERT(NVARCHAR(16),@PickUpTime,112) AND  [Time] = CONVERT(NVARCHAR(16),@Time,112))      

does not do it correctly on the time conversion any suggestions?

Cheers
0
RIAS
Asked:
RIAS
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
without concrete data as it is in the table and the variables, impossible to tell for sure

you may want to (re)read this article;:
https://www.experts-exchange.com/articles/1499/DATE-and-TIME-don't-be-scared-and-do-it-right-the-first-time.html
0
 
RIASAuthor Commented:
Any suggestions on how to check for null

example :

[REG] = @[REG]
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
NULL on which side?

depending on the context, and the possible values and data type of the column/variable, I either use an AND/OR expression or a isnull expresion

AND (  ( [REG] IS NULL AND @[REG] IS NULL )
       OR ( [REG] = @[REG] )
       )

Open in new window

AND (  ISNULL( ( [REG] , 'X$X' ) = ISNULL( @[REG] , 'X$X' ) )

Open in new window

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now