Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert below PL/SQL into T SQL

SQL
SELECT to_char(ADD_MONTHS( TRUNC(PARAM.start_date, 'Q'), 3*(LEVEL-1) ),'Q') dt,
ADD_MONTHS( TRUNC(PARAM.start_date, 'Q'), 3*(LEVEL-1) )   AS qstart,
ADD_MONTHS( TRUNC(PARAM.start_date, 'Q'), 3*(LEVEL) ) -1  AS qend
Posted

1 solution

The TO_CHAR equivalent in T-SQL is CONVERT.

SQL
CONVERT(varchar(20), myDate)


ADD_MONTHS translates to DATEADD

SQL
DATEADD(month, myDate)


The equivalent of Oracle TRUNC(date) is a COMBINATION of two CONVERT functions, one to convert to varchar and extract the time value and the other to convert it back to date.
 
Share this answer
 
v2
Comments
saurabh kumar mahto 31-Jan-14 1:34am    
and what about TRUNC ? what is its equivalent in T SQL ?
[no name] 31-Jan-14 4:28am    
Answer updated, please check.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900