tags:

views:

138

answers:

2

I'm returning a dataset using SubSonic.SqlQuery of two joined objects, but I can't seem to figure out how to perform this where clause:

Month(SubmittedOn)=Month(GETDATE()) AND Year(SubmittedOn)=Year(GETDATE())

I tried to do it like this, but it did not like the .IsEqualTo(string):

.Where("Month(SubmittedOn)").IsEqualTo("Month(getdate()")
A: 

Looks like you are missing a bracket. Try:

.Where("Month(SubmittedOn)").IsEqualTo("Month(getdate())")
RedFilter
Good catch, but that doesn't seem to fix it:SubSonic.SqlQueryException: Conversion failed when converting the varchar value 'Month(getdate())' to data type int.
Scott
I don't know SubSonic, but can you rewrite it as:.Where("Month(SubmittedOn) = Month(getdate())")
RedFilter
A: 

You can only pass in a value to a constraint method (IsEqualTo) in SubSonic so the following will get all the rows submitted in March:

.Where("Month(SubmittedOn)").IsEqualTo(3)

The following will get all rows submitted in the current month:

.Where("Month(SubmittedOn)").IsEqualTo(DateTime.Now.Month)
Adam
I am trying to only search by one column. I have a table with a 'SubmittedOn' DateTime column and I want to return all records that happened in the current month. In SQL MONTH(getdate()) will return the current month because MONTH is a SQL function. Here is the SQL code:SELECT * FROM Awards WHERE MONTH(SubmittedOn) = MONTH(getdate())Eventually I need to get the year in there too, but I can figure that out once I have the month in there: AND Year(SubmittedOn)=Year(GETDATE())Also: what are the code tags if I want to enter code into StackOverflow like the user in the first answer?
Scott
OK I think I see what you're trying to do now and I've updated my answer. You get code formatting by putting four spaces in front of each line you want formatted.
Adam
Thanks that was it!
Scott