Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default SQL Select statement with Date as

I'm pulling data into Excel using a SQL statement in VBA. I'd like to
pull an [updatedate] field and have it formatted in the format yyyy -
mm. I'm not sure how to do this however. I basically have this set
up right now.

Statement = "SELECT Insertby, Campaign, Resolution1, " & _
"Resolution2, Resolution3, Stage, MonthlyCost, " & _
"ProspectId " & _

I'd like to add into this something along the lines of

Format(UpdateDate,"yyyy - mm") AS UpdateMnthShrt

I'm not sure how to set the UpdateDate portion of the statement. Any
help would be GREATLY appreciated.

Thanks

Paul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SQL Select statement with Date as

Pepe,

Try the "To_Char" method.

TO_CHAR(UpdateDate, 'YYYY - MM')

HTH

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default SQL Select statement with Date as

Pepe,

Here's an idea which runs in Enterprise manager in SQL. Not sure how it will
work on a query from Excel, but worth a shot:

"SELECT Insertby, Campaign, Resolution1, Resolution2, Resolution3, Stage,
MonthlyCost, ProspectId, CONVERT(char(4), YEAR(UpdateDate)) + '-' +
CONVERT(char(2), MONTH(UpdateDate)) AS UpdateMnthShrt"

Robin Hammond
www.enhanceddatasystems.com


"Pepe" wrote in message
m...
I'm pulling data into Excel using a SQL statement in VBA. I'd like to
pull an [updatedate] field and have it formatted in the format yyyy -
mm. I'm not sure how to do this however. I basically have this set
up right now.

Statement = "SELECT Insertby, Campaign, Resolution1, " & _
"Resolution2, Resolution3, Stage, MonthlyCost, " & _
"ProspectId " & _

I'd like to add into this something along the lines of

Format(UpdateDate,"yyyy - mm") AS UpdateMnthShrt

I'm not sure how to set the UpdateDate portion of the statement. Any
help would be GREATLY appreciated.

Thanks

Paul



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default SQL Select statement with Date as

Robin, Thank you for the advice. It worked nicely for me. I have an
additional challenge now for you or anyone willing to help out. I
want to do something similar to what I did below, but this time
convert the UpdateDate into a Week Range (Sun - Sat). The format
would be

1/18/2004 - 1/24/2004

I had done something similar in Access with this formula:

Int((CDate(UpdateDate))-Weekday((CDate(UpdateDate)))+1) & " - " &
(Int((CDate(UpdateDate))-Weekday((CDate(UpdateDate)))+7)) AS
UpdateWeekRange

Thanks in advance for any help on this one.

Paul



"Robin Hammond" wrote in message ...
Pepe,

Here's an idea which runs in Enterprise manager in SQL. Not sure how it will
work on a query from Excel, but worth a shot:

"SELECT Insertby, Campaign, Resolution1, Resolution2, Resolution3, Stage,
MonthlyCost, ProspectId, CONVERT(char(4), YEAR(UpdateDate)) + '-' +
CONVERT(char(2), MONTH(UpdateDate)) AS UpdateMnthShrt"

Robin Hammond
www.enhanceddatasystems.com


"Pepe" wrote in message
m...
I'm pulling data into Excel using a SQL statement in VBA. I'd like to
pull an [updatedate] field and have it formatted in the format yyyy -
mm. I'm not sure how to do this however. I basically have this set
up right now.

Statement = "SELECT Insertby, Campaign, Resolution1, " & _
"Resolution2, Resolution3, Stage, MonthlyCost, " & _
"ProspectId " & _

I'd like to add into this something along the lines of

Format(UpdateDate,"yyyy - mm") AS UpdateMnthShrt

I'm not sure how to set the UpdateDate portion of the statement. Any
help would be GREATLY appreciated.

Thanks

Paul

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Case Statement Katie Excel Worksheet Functions 13 December 1st 08 07:32 PM
If Statement to select a letter Karl Excel Worksheet Functions 3 February 8th 08 04:01 PM
Adding SQL Select Statement Pepe[_2_] Excel Programming 1 January 29th 04 02:19 AM
Wildcard character with Select Statement Mike Excel Programming 1 December 12th 03 07:21 PM
Convert If..Else to Select Case Statement. Sheela Excel Programming 1 July 25th 03 09:28 AM


All times are GMT +1. The time now is 02:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"