sql_language thread: HELP needed extracting records from DB on a monthly basis question?
Look up DatePart() and GetDate() in SQL Server Books Online.
Just a tip. When writing SQL statements it is usual to write out SQL
keywords in ALL CAPS, making the whole thing a whole lot easier to read, eg:
SELECT cv.Organization, hu.LastName, hu.FirstName, wl.Access_Date,
wl.Access_Page, wl.Access_Opertn, wl.Report_Name, wl.Patient_Last,
wl.Patient_First, wl.Patient_ID, crr.Descrptn, COUNT(*) AS Times_Accessed
FROM web_log wl
LEFT OUTER JOIN hcin_user hu
ON wl.hcin_user_id = hu.hcin_user_id
The addition of line feeds will also make the whole thing easier to read:
SELECT
cv.Organization
, hu.LastName
, hu.FirstName
, wl.Access_Date
, wl.Access_Page
, wl.Access_Opertn
, wl.Report_Name
, wl.Patient_Last
, wl.Patient_First
, wl.Patient_ID
, crr.Descrptn
, COUNT(*) AS Times_Accessed
FROM
web_log wl
LEFT OUTER JOIN
hcin_user hu
ON
wl.hcin_user_id = hu.hcin_user_id
LEFT OUTER JOIN
...
...
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <savoym@h...>
Subject: [sql_language] HELP needed extracting records from DB on a monthly
basis question?
: I am working on a stored procedure whereby I would like to extract all
: the records on a monthly basis when I run this stored procedure on the
: last day of the month, I guess via SQL job(?). I was working from a
: template to work on date function basAny direction or help would be
: appreciated. Thank you.
:
: Here is the SP code I am working with:
:
: select cv.Organization, hu.LastName, hu.FirstName, wl.Access_Date,
: wl.Access_Page, wl.Access_Opertn, wl.Report_Name, wl.Patient_Last,
: wl.Patient_First, wl.Patient_ID, crr.Descrptn, count(*) AS Times_Accessed
: from web_log wl
: left outer join hcin_user hu
: on wl.hcin_user_id = hu.hcin_user_id
: left outer join pss_customer_services.dbo.cust_view cv
: on hu.helpdesk_clientid = cv.clientid
: left outer join pss_customer_services.dbo.[name] n
: on cv.clientid = n.clientid
: left outer join clinical_reporting_relationships crr
: on wl.relationship_id = crr.relatnshp_id
: where hu.isphysician = 0
: and cv.last NOT LIKE 'NOT IN SYSTEM%'
: and n.name_type = 1
: and wl.access_date = 'MONTHLY DATE VARIABLE GOES HERE(?)'
: group by access_date, access_page, access_opertn, report_name,
: cv.organization, hu.lastname, hu.firstname, patient_last, patient_first,
: patient_id, crr.descrptn
: order by cv.organization, hu.lastname, hu.firstname, access_date desc,
: access_page, report_name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~