question

simhadri avatar image
simhadri asked

from table Retrieving data by months parameters...

I have table name time_data in that it holds (docid,docdate,usertype,fromdate,todate,userid ) columns date format is 'dd/mm/yyyy' now i want to retrieve the data by giving the run time parameters month and year ...'JUN' and '2013' ..... for suppose if i give month jan and year 2013 in that jan month it what date i have entered ..has to come ...total sum of users..how to write a query for this.
sql-server-2008sqloracleoracle-sql-developer
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered
In SQL Server / T-SQL, you could do something like: --Assuming @Month3Letters is the three character month, and @Year is the year -- also assuming that you're matching on the fromdate field DECLARE @MonthNum int SELECT @MonthNum = 1 + ((PATINDEX(@Month3Letters, 'JANFEBMARAPTMAYJUNJULAUGSEPOCTNOVDEC') - 1) / 3) SELECT COUNT(*) FROM time_data WHERE YEAR(fromdate) = @Year AND MONTH(fromdate) = @MonthNum (Untested, written without the aid of caffeine, probably woefully inefficient...)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.