Getting month from Date field in SQL DATABASE

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have an ASP.NET application. I am using a dataset for loading data (based
on user input month & company Name) from SQL database. I have the query as ::

SELECT CompanyName, Date , CEO from TABLE WHERE (CompanyName=@a &&

But how do I get the month part from the Date field in the database so that
when the user enters the month in text box, records can be selected based on
the month.

Any help is appreciated.
 
If I understand your question, you want to parameterize your query with input
month and company name. If this is right, you need to add to your WHERE
clause
CompanyName = @CompanyName AND
DATEPART(MONTH, [Date]) = @InputMonth

Remember @InputMonth needs to be an Integer, as that is what DATEPART will
return.

JT
 
Back
Top