Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Date

Author  Topic 

baska123
Yak Posting Veteran

64 Posts

Posted - 2006-06-23 : 16:48:44
How to extract just a month from a string date like "1/13/2006"

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-23 : 16:50:55
You can use the MONTH function.

Tara Kizer
aka tduggan
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2006-06-23 : 16:59:00
Here is the statement

SET @BEFor_Month = (Select isnull(sum(isnull(Amount,0)),0) from BILLING_TIME_COSTS where msps_proj_id=@WPROJ_ID and month_abbrev=@MONTH_ABBREV and BILLABLE='1' and MONTH(DT_Charged)=@MONTH)

DT_Charged is DateTime and @MONTH is nvarchar(8)
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2006-06-23 : 17:01:27
Here is the error that I am getting when running SP:
Syntax error converting the nvarchar value 'APR' to a column of data type int.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-23 : 17:05:54
The functions return the month number not name. You will need to code for that.

Tara Kizer
aka tduggan
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2006-06-23 : 17:08:40
any pointers to the code? URGENT!!!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-23 : 17:10:22
Ummm, I can't see your code so I don't know how to help you with your urgent problem. Have you opened up SQL Server Books Online to check out the MONTH function or maybe even DATEPART?

Tara Kizer
aka tduggan
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2006-06-23 : 17:18:20
No i did not. Are they on MSDN?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-23 : 17:20:57
Books Online is on your machine if you have Enterprise Manager and Query Analyzer installed. Start..Programs..Microsoft SQL Server..Books Online. Go to Index tab and type in MONTH. Then check out DATEPART.

Tara Kizer
aka tduggan
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2006-06-23 : 17:24:59
I checked it, but it still returns number instead of the name. I am totally new to t-sql so do not know where to find info yet.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-23 : 17:30:33
It will return a number. The functions return an int. So you need to code for this fact. It will not return the name. You must write that part.

Tara Kizer
aka tduggan
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2006-06-23 : 17:37:20
I know, i am using if then else statement that is erroring on me because t-sql conditional is different from what i know so far.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-23 : 17:54:43
Show us what you have. We should be able to help you.

Tara Kizer
aka tduggan
Go to Top of Page

VladRUS.ca
Starting Member

23 Posts

Posted - 2006-06-23 : 21:29:28
quote:
Originally posted by baska123

How to extract just a month from a string date like "1/13/2006"

select DATENAME ( month , getdate())
Go to Top of Page
   

- Advertisement -