If you want to build a DateTime from values… suppose you have columns in your table, say fyear and fmonth and you want to make a DateTime value for doing some checkings….

convert(datetime,cast([fmonth] as varchar(2))+’-01-’+cast([fyear] as varchar(4)))

Eg:

select *
from pamodea
where convert(datetime,cast([fmonth] as varchar(2))+’-01-’+cast([fyear] as varchar(4))) between @startdate and @enddate

VN:F [1.1.6_502]
Rating: 0.0/5 (0 votes cast)
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • DotNetKicks
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati

Related posts:

  1. T-SQL Find previous month
  2. What is the difference between CAST and CONVERT in SQL?
  3. My name is 0×5052415645454e in SQL ;)
  4. Winforms Calendar code – C#
  5. SQL – Convert columns to a row (concatenation)