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.
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)))ErrorMsg 245, Level 16, State 1, Line 14Conversion 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 DATETIMESET @yourDate = GETDATE()if(DATEPART(MONTH, @yourDate)<=3)select (datename(year,DATEADD(YEAR,1,@yourDate)+'/'+ datename(YEAR, @yourDate)) )elseselect (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] |
|
|
srisha
Starting Member
38 Posts |
Posted - 2013-06-06 : 02:03:15
|
Accounting year "Physical year -last year"this type only i needthanks your replySRISHA |
|
|
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] |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-06-06 : 02:09:12
|
If block should be as followsquote: Originally posted by khtan this is what you want ?DECLARE @yourDate DATETIMESET @yourDate = GETDATE()if(DATEPART(MONTH, @yourDate)<=3)select datename(year,DATEADD(YEAR,1,@yourDate))+'/'+ datename(YEAR, @yourDate)elseselect (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 |
|
|
srisha
Starting Member
38 Posts |
Posted - 2013-06-06 : 02:12:36
|
Thanks working fineSRISHA |
|
|
srisha
Starting Member
38 Posts |
Posted - 2013-06-06 : 02:21:31
|
select year(POSTDATE) from OEINVHPostdate column is in date datatype.ErrorMsg 8115, Level 16, State 2, Line 2Arithmetic overflow error converting expression to data type datetime. |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
|
|
|
|
|
|