遍历所有sql字段 [英] going through all sql fields

查看:172
本文介绍了遍历所有sql字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,正在运行一个查询,它返回了我想要的多行,完美.我不得不发送消息以关注移动设备,所以我为此编写了程序,但问题是我无法将消息发送到不同的移动设备,即不同行返回的编号.简而言之,我的意思是我想将消息发送到查询返回的所有数字.

i am running through a problem, i am running a query and it returns multiple rows as i wanted, perfect. I had to send message to concern mobile no so i wrote procedure for it that''s working but problem is that i am not able to send message to different mobile no i.e. no.s returned by different rows. In short i mean that i want to send messages to all numbers that are returned by query.

Select CL.[Subject],  D.Name as Designation,  D.MobileNo, CL.LetterNo,'Please Reply To Our Letter No : ' + convert(varchar(50),CL.LetterNo) as SMSMessage
  from CPOCMS.dbo.ComposedLetter CL 
  Join CPOCMS.dbo.Designations D on  CL.Designation_ID = D.DesignationID

 where   convert(date,CL.DeadLineDate) = Convert(date,DATEADD(DAY,1,GETDATE()))

 Exec dbo.ADD_SMS_InQueue 'Requires number', 'requires message'

推荐答案

您可以使用游标在所有行中循环.但是,为什么不执行批量插入而不是在循环中调用ADD_SMS_INQueue?
You could use a cursor and loop through all the rows. But why dont you do a bulk insert instead of calling the ADD_SMS_INQueue in a loop?


如soumyajayaraj所建议的,您可以使用CURSOR-如果您没有在如何在Sql中使用游标之前使用过 [ ^ ]

警告-大量数据时游标会变得非常慢.

我打算建议使用函数而不是SP,因为您可以将其合并到查询中,但是AFAIK不能通过函数发送电子邮件,而我所做的少量研究并没有提供其他选择(我只是提及它以备将来使用)
As suggested by soumyajayaraj you could use a CURSOR - here''s a CP Tip if you haven''t used one before How to use Cursor in Sql[^]

Warning - cursors can get very slow with large quantities of data.

I was going to suggest using a function instead of an SP as you could have incorporated that into your query, but AFAIK you cannot send an email from a function, and the little research I''ve done did not offer an alternative (I only mention it for possible future use)


这篇关于遍历所有sql字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆