Getting month from Date field in SQL DATABASE

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top