| Author |
Topic |
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 15:29:31
|
| I need to create a query which emails each store their location information. So it's one email which has the store location information which is going to 37 indicidual stores with there own information.i think this is called email looping? am new at this so not too sure.so far i have the scrip to generate the email of the query results to email addresPLEASE HELP BELWO IS THE QUERY THAT I HAVE EXEC msdb.dbo.sp_send_dbmail@recipients = 'dtrivedi@musicarts.com',@body= 'BODY OF THE EMAIL' @query='SELECT [LOCATION],[CUSTOMER],[ACCOUNT],[CUSTOMER_NAME],[PHONE] FROM vw_PAST_DUE_LESSONS_EZPAY]' ,@subject = 'EZ', |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 15:35:11
|
| yes i created at temp table |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 15:41:34
|
| loc cname 1 adam1 dana2 doyel2 brian2 april3 brent3 amber4 ryan4 nickso this is just sample data i have much more data to sendbut what i basically need it to do is runa a query for each store select location then find the cname for that location and then email that query to that specific store |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 15:44:51
|
| this exec statement will have the email EXEC msdb.dbo.sp_send_dbmail@recipients = 'dtrivedi@musicarts.com',@body= 'BODY OF THE EMAIL' @query='SELECT [LOCATION],[CUSTOMER],[ACCOUNT],[CUSTOMER_NAME],[PHONE] FROM vw_PAST_DUE_LESSONS_EZPAY]' ,@subject = 'EZ',the diffrence will be CNAME for each location |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 15:48:40
|
| ohh i thought i can put that manually in there...if nto i guess i should add them to my temp file?? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 15:51:40
|
| sorry am new at this...ok so im adding the location emails to the temp location file |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 16:00:23
|
| i'm going to finish entering the emails and then try this lets hope it worksthanks alot |
 |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 16:15:22
|
| ok am done entering emails now am going to try this code...can you tell me what @id int is? and how will it send the data from teh other query??? |
 |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 16:15:55
|
| send these query results to those locations and emails EXEC msdb.dbo.sp_send_dbmail@recipients = 'dtrivedi@musicarts.com',@body= 'BODY OF THE EMAIL' @query='SELECT [LOCATION],[CUSTOMER],[ACCOUNT],[CUSTOMER_NAME],[PHONE] FROM vw_PAST_DUE_LESSONS_EZPAY]' ,@subject = 'EZ', |
 |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 16:26:41
|
| i am getting this errori dont know what it means Must declare the scalar variable "@locations".DECLARE @locations varchar(50), @email varchar(100)declare t_loccursor for select locations,storeemail from #ezpaylocopen t_locfetch next from t_locinto @locations, @emailwhen i run the fetch statement im getting the error |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dtrivedi
Posting Yak Master
153 Posts |
Posted - 2010-07-19 : 16:50:11
|
| I am confused all i need to do is take the results of this 'SELECT [LOCATION],[CUSTOMER],[ACCOUNT],[CUSTOMER_NAME],[PHONE] FROM vw_PAST_DUE_LESSONS_EZPAY]'and email it to diffrent locations that come up in that querythe emails for the locations are saved in a #temp table |
 |
|
|
|