Solved

SQL Query

Posted on 2016-08-24
3
20 Views
Last Modified: 2016-08-24
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
Comment
Question by:RIAS
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41768489
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
 

Author Comment

by:RIAS
ID: 41768513
Any suggestions on how to check for null

example :

[REG] = @[REG]
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 41768577
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Creating and Managing Databases with phpMyAdmin in cPanel.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now