Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2007, 11:36 PM
Authorized User
 
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datpart and convert function

I have thid query,

SELECT DISTINCT DATEPART(year, dateprinted) +Convert(VarChar(20), dateprinted, 103) AS Year
FROM tbl_pcounterlog
ORDER BY Year

BWhen I pars it it says that it is okay yet when I run it I get the following error,

Syntax error converting the varchar value '01/02/2007 08:11' to a column of data type int.

What am I doing wrong

Thanks

Greg

 
Old February 14th, 2007, 12:47 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

DATEPART returns an INT and has no implicit conversion to the VARCHAR in your CONVERT... change DATEPART to DATENAME and that problem will go away.

--Jeff Moden
 
Old February 14th, 2007, 04:32 PM
Authorized User
 
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Jeff

Changing to DATENAME does not work either.

Here is the senareo. I have an app that captures all printing info and when I import the apps log file into a sql table (to creat reports using RS 200) the date is imported into a column which has a data type of varchar (20). I am wanting to write this query in my RS report.

[red][red]SELECT DISTINCT DATENAME (year, dateprinted) +Convert(VarChar(20), dateprinted, 103) AS Year
FROM tbl_pcounterlog
ORDER BY Year

Is there a better war to do this - like importing the data into a temp table and then using a SP to copy date and change the date format to DateTime and then query the table with:

SELECT DISTINCT DATEPART (year, dateprinted) AS Year
FROM tbl_pcounterlog
ORDER BY Year

Thans

Greg

 
Old February 15th, 2007, 03:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

How do you import data from log file into sql table? Do you use DTS package or BCP utility? With BCP or BULK INSERT you can have a format file defined that is referenced by the BCP utility while importing data and you can avoid storing it into a temp table and so on. It also depends on how the data is stored into the log file from which you are importing data.

Cheers

_________________________
- Vijay G
Strive for Perfection
 
Old February 16th, 2007, 01:39 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Ah... I get it... of course it would be better to have dates in DATETIME columns but I believe the following will do what you want...

SELECT DISTINCT DATEPART (year, CONVERT(DATETIME,dateprinted,103)) AS Year
FROM tbl_pcounterlog
ORDER BY Year


--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
convert string to function austinf Javascript 3 September 19th, 2008 03:25 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
convert asp function to asp.net debuajm General .NET 0 June 11th, 2004 11:03 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM
Query String Cast or Convert function hoffmann Access 6 February 25th, 2004 01:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.