SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 convert varchar on weekly date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

czajkuss
Starting Member

3 Posts

Posted - 09/13/2013 :  05:48:25  Show Profile  Reply with Quote
Hi,
I have 2 columns in table : date and sales volume. Date is in varchar format YYYYMMDD and I need convert them on format YYYY - week. Do you have any idea how deal with this problem?

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 09/13/2013 :  06:41:20  Show Profile  Reply with Quote
DECLARE @date vARCHAR(10) = '20130913' --YYYYMMDD
SELECT DATENAME(year,@date) + '-' + DATENAME(quarter,@date) AS [YYYY-quater],
DATENAME(year,@date) + '-' + RIGHT('00' + CAST(DATEPART(month,@date) AS varchar(2)),2) + '-' + DATENAME(ISO_week,@date) AS [YYYY-MM-Week]


--
Chandu
Go to Top of Page

bagaisamang
Starting Member

2 Posts

Posted - 09/21/2013 :  11:41:34  Show Profile  Reply with Quote
DELIMITER $$
create function readerNumber (@id int)
returns varchar(5)
begin
return 'R' + right('0000' + convert(varchar(10),@id), 4)
END$$
gives an error plis help
ERROR 1064(42000): you have an error in your SQL syntax; check the manual that corresponds to your MySQL version for the right syntax to use near'@id int) at line 1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 09/22/2013 :  03:00:51  Show Profile  Reply with Quote
quote:
Originally posted by bagaisamang

DELIMITER $$
create function readerNumber (@id int)
returns varchar(5)
begin
return 'R' + right('0000' + convert(varchar(10),@id), 4)
END$$
gives an error plis help
ERROR 1064(42000): you have an error in your SQL syntax; check the manual that corresponds to your MySQL version for the right syntax to use near'@id int) at line 1


its obvious that you're using MySQL. This is MS SQL Server forum. You may be better off trying this in some MySQL forums to get specific syntax help

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22742 Posts

Posted - 09/22/2013 :  09:24:13  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
return 'R' + right('0000' + convert(varchar(10),@id), 4)

should be

return concat('R' , right(concat('0000' , @id), 4))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000