question

mahi222 avatar image
mahi222 asked

I need help for extracting data from date column very urgent

i have a column FiscalYear='FY2014' but I need output like 'FY14' how to extract it I tried using functions like left and right
functions
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
ASK SQL Server Central runs by you voting. For all helpful answers below, please indicate this by clicking on the thumbs up next to those answers. If any one answer lead to a solution, please indicate this by clicking on the check mark next that answer.
0 Likes 0 ·
David Wimbush avatar image
David Wimbush answered
If they always have the same format, you could use this: 'FY' + reverse(substring(reverse(FiscalYear),1,2)). I just hope you don't have any dates that are not 2000-2999. (I worked on the Y2K 'bug' and still bear the scars!) In my opinion, FY2014 is actually better.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

erlokeshsharma08 avatar image
erlokeshsharma08 answered
DECLARE @VA VARCHAR(6) SET @VA = 'fy2099' select CASE WHEN right(@VA,'3') < 100 THEN LEFT(@VA,'2') +right(@VA,'2') ELSE @VA END AS LOK
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Alvin Ramard avatar image
Alvin Ramard answered
What about: REPLACE(FiscalYear, '20', '')
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Venkataraman avatar image
Venkataraman answered
SELECT 'FY'+ RIGHT(RIGHT('fy2014',4),2)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.