Solved

SQL Query

Posted on 2016-08-24
3
24 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 143

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 143

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query Syntax 17 41
length of the password hash sha1:64000 to set sql field property. 13 65
Combining Queries 7 27
Need return values from a stored procedure 8 18
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.

789 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