Groups | Blog | Home
all groups > sql server (alternate) > october 2005 >

sql server (alternate) : SQL Convert function!!


v0lcan0
10/6/2005 5:36:46 PM
I’m trying to cast and integer type to a varchar and then concatenate
two varchar and ’01’ and convert it into datetime with the following
code:

CONVERT(datetime, { fn CONCAT({ fn CONCAT(CAST(PeriodYear AS varchar),
CAST(PeriodMonth AS varchar)) }, ’01’) }, 112) AS date

It gives an error saying syntax error converting datetime from
character string.

Any help appreciated!!

thx..

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/General-Discussions-SQL-Convert-function-ftopict261333.html
Steve Kass
10/7/2005 12:00:00 AM
See what you get from

select PeriodYear, PeriodMonth
from yourTable
where PeriodYear not between '1753' and '9999'
or (PeriodMonth not between '1' and '12'
and PeriodMonth not between '01' and '09')

Steve Kass
Drew University

[quoted text, click to view]
helmut woess
10/7/2005 12:00:00 AM
Am 6 Oct 2005 17:36:46 -0400 schrieb v0lcan0:

[quoted text, click to view]

If PeriodMonth is < 10 then the result in your statement would be something
like 2005701, which is an invalid datae indeed. And why concat? A simple
"+" is enough. For example:
select CONVERT(datetime,CAST(PeriodYear AS varchar) +
RIGHT('0' + CAST(PeriodMonth AS varchar),2) + '01', 112) AS date
should do the job, if year and month are valid values.

bye,
v0lcan0
10/12/2005 8:28:51 PM
[quoted text, click to view]

thx for that steve..

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/General-Discussions-SQL-Convert-function-ftopict261333.html
v0lcan0
10/12/2005 8:28:53 PM
[quoted text, click to view]

thx helmut...being a new SQL programmer, your suggestion is really
worthwhile.

thanks again

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/General-Discussions-SQL-Convert-function-ftopict261333.html
AddThis Social Bookmark Button