473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SQL Convert function!!

Im 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-Disc...ict261333.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=900084
Oct 6 '05 #1
4 15782
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

v0lcan0 wrote:
Im 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..

Oct 7 '05 #2
Am 6 Oct 2005 17:36:46 -0400 schrieb v0lcan0:
Im 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..


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,
Helmut
Oct 7 '05 #3
"" wrote:
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

v0lcan0 wrote:
Im 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..


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-Disc...ict261333.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=904391
Oct 13 '05 #4
"" wrote:
Am 6 Oct 2005 17:36:46 -0400 schrieb v0lcan0:
Im 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..


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,
Helmut


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-Disc...ict261333.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=904392
Oct 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bill | last post by:
I'm getting the following error: Disallowed implicit conversion from data type varchar to data type money, table 'bill.dbo.cart', column 'price'. Use the CONVERT function to run this query. ...
1
by: shank | last post by:
I'm getting the following error... Microsoft OLE DB Provider for SQL Server error '80040e07' Disallowed implicit conversion from data type varchar to data type money, table 'wsOrders', column...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: veereshai | last post by:
i want to copy the functions from my source file into a new file...and convert each function into a new object file by compiling it. now, i want to invoke the function using the object file i have...
5
by: Andy Sutorius | last post by:
Hi, I am attempting to convert this vb function to csharp but I am getting stuck on the if statement dt.Rows(iLoop)("FAQCategoryID")). The compiler says "method name expected" and underlines...
1
by: Ken Hughes | last post by:
Can anyone help me with this one... I am doing an API call and need to convert a function address to a IntPtr for a callback... e.g. RasDial(X,X,X,Pointer to Callback Function,X) 'Pointer...
0
by: Wes Peters | last post by:
I have a situation where I want to filter records for a given day. The field that stores the date/time uses the date() function as a default value, kind of a date/time stamp for the record. The...
1
by: Wes Peters | last post by:
I have a situation where I want to filter records for a given day. The field that stores the date/time uses the date() function as a default value, kind of a date/time stamp for the record. The...
1
by: ashishtech | last post by:
In the following query D_CNT_LINE_EXPIRE comparison with '2008-09-19' is failing altough value is there in this field. D_CNT_LINE_EXPIRE is a timestamp field in SQLSERVER table CCG03. I doubt...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.