SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Error in Drop Create stored procedure.


Error in Drop Create stored procedure.

Author
Message
JJR333
JJR333
SSC-Enthusiastic
SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)

Group: General Forum Members
Points: 102 Visits: 277
Am I correct to assume that @myDate is our starting point?
And that CONVERT only changes the display of the date string according to the added parameter (111 or 105).
Then the calculations should give the same results...
J.

How do you "tell" SQL Server that @myDate is in this format: yyyy-mm-dd?



Declare @myDate varchar(50)
Set @myDate = '2014-04-08'

SELECT CONVERT( char(20), CONVERT( datetime, @myDate))

select (convert(datetime, @myDate,111))+22
select convert(char(20), (convert(datetime, @myDate,111))+22)

select (convert(datetime, @myDate,105))+22
select convert(char(20), (convert(datetime, @myDate,105))+22)



This gives identical results:


Declare @myDate varchar(50)
Set @myDate = '2014/dec/10' --yyyy-mm-dd

SELECT CONVERT( char(20), CONVERT( datetime, @myDate))

select (convert(datetime, @myDate,111))+22
select convert(char(20), (convert(datetime, @myDate,111))+22)

select (convert(datetime, @myDate,105))+22
select convert(char(20), (convert(datetime, @myDate,105))+22)


Luis Cazares
Luis Cazares
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17098 Visits: 19122
What about using the code 120?
CONVERT( datetime, @myDate, 120)




Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
JJR333
JJR333
SSC-Enthusiastic
SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)

Group: General Forum Members
Points: 102 Visits: 277
I might strip out the "-" to prevent issues.
See this post, last message.

Here I get consistant results:

Declare @myDate varchar(50)
Set @myDate = '20141210' --yyyymmdd


SELECT CONVERT( char(20), CONVERT( datetime, @myDate))

select (convert(datetime, @myDate,111))+22
select convert(char(20), (convert(datetime, @myDate,111))+22)

select (convert(datetime, @myDate,105))+22
select convert(char(20), (convert(datetime, @myDate,105))+22)

select (convert(datetime, @myDate,120))+22
select convert(char(20), (convert(datetime, @myDate,120))+22)



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search