Click here to Skip to main content
15,037,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello professionals


i have a problem in Sql Server that there is in my table separate columns for year and month and date with valid value.
i need to add them and make a valid date from that all columns becouse i need to run Between Query.

so can any one help me......?
Posted

You can try some thing like this...
SQL
Declare @Year varchar ='2013', @Month varchar ='7', @Day varchar ='1'
Select Convert(Date, @Year+'-'+@Month +'-'+ @Day)-- Any Version
SELECT DATEFROMPARTS(2012,7,1)  -- For Sql Server 2012 and Above

DateFromParts-MSDN
Cast And Convert
Convert W3Schools
   
v2
Comments
Shubh Agrahari 14-Sep-13 1:41am
   
thanks friend but i done this..........by this
select CAST(CAST(@ToYear AS varchar) + '-' + CAST(@ToMonth AS varchar) + '-' + CAST(1 AS varchar) AS DATE) as ToDate from T_PayBill
Raja Sekhar S 14-Sep-13 2:38am
   
You are welcome...
thanks guys i solved it myself.......

with this code..

select CAST(CAST(@ToYear AS varchar) + '-' + CAST(@ToMonth AS varchar) + '-' + CAST(1 AS varchar) AS DATE) as ToDate from T_PayBill
   

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