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 2012 Forums
 Transact-SQL (2012)
 convert varchar on weekly date

Author  Topic 

czajkuss
Starting Member

3 Posts

Posted - 2013-09-13 : 05:48:25
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-09-13 : 06:41:20
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 - 2013-09-21 : 11:41:34
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

52326 Posts

Posted - 2013-09-22 : 03:00:51
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

22864 Posts

Posted - 2013-09-22 : 09:24:13
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
   

- Advertisement -