Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
swims01
Yak Posting Veteran
59 Posts |
Posted - 2009-05-19 : 14:23:22
|
Having done a little research it appears that you cannot use variables within SQL's jobs. Is this correct?I can now send emails through SQL 2005 (thanks visakh16 =) using simple queries. The goal was to use these jobs to send out data from more complex queries. What are my options to do this?/* Primary membership classes that are used within the IN statements */--DROP TABLE #PrimaryClassesCREATE TABLE #PrimaryClasses (classID int)INSERT INTO #PrimaryClassesSELECT 22 UNION ALLSELECT 25 UNION ALLSELECT 28 UNION ALLSELECT 29 UNION ALLSELECT 30 UNION ALLSELECT 36 UNION ALLSELECT 37 UNION ALLSELECT 38 UNION ALLSELECT 39 UNION ALLSELECT 50 UNION ALLSELECT 51 UNION ALLSELECT 52 UNION ALLSELECT 63 UNION ALLSELECT 64 UNION ALLSELECT 65SELECT tblFacility.vcFacilityName AS Club, COUNT(CASE WHEN tblmembers.sistatusid = '1' AND classid IS NOT NULL THEN tblmembers.vcMemberID ELSE NULL END) AS [Memberships]FROM tblMembers INNER JOIN tblContracts ON tblMembers.iMembershipContractid = tblContracts.iContractId INNER JOIN tblFacility ON tblMembers.vcCurrentFacilityID = tblFacility.vcFacilityID LEFT OUTER JOIN [#PrimaryClasses] ON classID = tblContracts.siMembershipClassIdwhere tblFacility.vcFacilityName <> 'Corporate' and tblMembers.cMemberCategory = 'M'GROUP BY tblFacility.vcFacilityName |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-05-19 : 14:58:44
|
Make the query text stored in a variable.Assign that variable to matching parameter the sp_dbsendmail procedure. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
swims01
Yak Posting Veteran
59 Posts |
Posted - 2009-05-19 : 15:01:52
|
| Thanks Peso. I'll do some searching to decifer that =) Can you give me an example or a link to a page that describes how to do that in more detail? |
 |
|
|
swims01
Yak Posting Veteran
59 Posts |
Posted - 2009-05-19 : 15:04:44
|
| * EDIT * GOT IT!!!Thanks! |
 |
|
|
|
|
|