x

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.

more ▼

asked Jun 21, 2013 at 08:25 AM in Default

avatar image

simhadri
10 4 4 6

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Jun 22, 2013 at 07:11 PM

avatar image

ThomasRushton ♦♦
41.6k 20 50 53

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2159
x1114
x434
x29

asked: Jun 21, 2013 at 08:25 AM

Seen: 664 times

Last Updated: Jun 22, 2013 at 07:11 PM

Copyright 2017 Redgate Software. Privacy Policy