Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

Converting a date string to date type

$
0
0

Hi,

Can anyone please help. I am working on a reporting project using Birt

The issue I'm having now is on the sql server side in my query I have this query set 

DECLARE @JDate DATE      
SELECT FORMAT(JDate,'MMM-yyyy')  AS JMonth
FROM dbo.Table1
WHERE CAST(JtDate AS DATE) BETWEEN '2017-01-01' AND '2018-03-31'
GROUP BY YEAR(JDate) * 100 + MONTH(JDate),FORMAT(JDate,'MMM-yyyy')
Order BY YEAR(JDate) * 100 + MONTH(JDate)

Which works great. Gives me the output i want as
Apr 2017
May 2017
Jun 2017
Jul 2017

In Birt this is pulled in Computed Columns as a string I need to turn this string to a date type. Either using javascript expression to format as i want above or change my query in sql server. Not sure best way to achieve this. 

If i ran this query in SQL Server 

DECLARE @JDate DATE      
SELECT CAST(JDate AS DATE) AS JMonth
FROM dbo.Table1
WHERE CAST(JtDate AS DATE) BETWEEN '2017-01-01' AND '2018-03-31'
GROUP BY YEAR(JDate) * 100 + MONTH(JDate),CAST(JDate AS DATE)
Order BY YEAR(JDate) * 100 + MONTH(JDate)
I get the following output some

I need the format to be
Apr 2017 
May 2017 
Jun 2017 
Jul 2017

In both columns.

Thanks in advance



Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>