?
Solved

SQL Query

Posted on 2016-08-24
3
Medium Priority
?
30 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

800 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