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
 General SQL Server Forums
 New to SQL Server Programming
 accounting year

Author  Topic 

srisha
Starting Member

38 Posts

Posted - 2013-06-06 : 01:49:27
DECLARE @yourDate DATETIME
SET @yourDate = GETDATE()
if(DATEPART(MONTH, @yourDate)<=3)
select (datepart(year,DATEADD(YEAR,1,@yourDate)+'/'+ DATEPART(YEAR, @yourDate)) )
else
select (DATEPART(YEAR, @yourDate)+'/'+datepart(year,DATEADD(YEAR,-1,@yourDate)))


Error
Msg 245, Level 16, State 1, Line 14
Conversion failed when converting the varchar value '/' to data type int.

removed the '/'
DECLARE @yourDate DATETIME
SET @yourDate = GETDATE()
if(DATEPART(MONTH, @yourDate)<=3)
select (datepart(year,DATEADD(YEAR,1,@yourDate)+'-'+ DATEPART(YEAR, @yourDate)) )
else
select (DATEPART(YEAR, @yourDate)+'-'+datepart(year,DATEADD(YEAR,-1,@yourDate)))

Answer is ='4025'
please help me

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-06-06 : 02:00:39
this is what you want ?

DECLARE @yourDate DATETIME
SET @yourDate = GETDATE()
if(DATEPART(MONTH, @yourDate)<=3)
select (datename(year,DATEADD(YEAR,1,@yourDate)+'/'+ datename(YEAR, @yourDate)) )
else
select (datename(YEAR, @yourDate)+'/'+datename(year,DATEADD(YEAR,-1,@yourDate)))

Note that datepart() returns an integer. You can't concatenate an integer with '/'. Instead use datename() which return the result in string


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

srisha
Starting Member

38 Posts

Posted - 2013-06-06 : 02:03:15
Accounting year

"Physical year -last year"
this type only i need

thanks your reply

SRISHA
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-06-06 : 02:08:30
so you have tried the query that i have posted ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-06 : 02:09:12
If block should be as follows
quote:
Originally posted by khtan

this is what you want ?

DECLARE @yourDate DATETIME
SET @yourDate = GETDATE()
if(DATEPART(MONTH, @yourDate)<=3)
select datename(year,DATEADD(YEAR,1,@yourDate))+'/'+ datename(YEAR, @yourDate)
else
select (datename(YEAR, @yourDate)+'/'+datename(year,DATEADD(YEAR,-1,@yourDate)))

Note that datepart() returns an integer. You can't concatenate an integer with '/'. Instead use datename() which return the result in string


KH
[spoiler]Time is always against us[/spoiler]





--
Chandu
Go to Top of Page

srisha
Starting Member

38 Posts

Posted - 2013-06-06 : 02:12:36
Thanks working fine
SRISHA
Go to Top of Page

srisha
Starting Member

38 Posts

Posted - 2013-06-06 : 02:21:31

select year(POSTDATE) from OEINVH
Postdate column is in date datatype.

Error
Msg 8115, Level 16, State 2, Line 2
Arithmetic overflow error converting expression to data type datetime.
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-06 : 03:27:05
Duplicate thread:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=185874
Check the solution there only

--
Chandu
Go to Top of Page
   

- Advertisement -