Author |
Topic |
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2010-09-07 : 14:40:12
|
hiassume that we have table for users(user_id,user_name,pwd,...)and we have a table named mails(mail_id,sender,reciever,message,isReaded) and mail_id is an identity fieldscenario is each user can send email for another user and ther is no problem here, but there is a time which admin user wanna send an email to all users, how can i write sql command for that?please help.thanks****<< I Love MTN.SH >>**** |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2010-09-07 : 14:43:38
|
hifrom my applicationsimply i wanna use a sqlcommand in asp.netthanks****<< I Love MTN.SH >>**** |
 |
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2010-09-07 : 14:44:51
|
i know how to use sqlcommand but i don't know what command text i have to use****<< I Love MTN.SH >>**** |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2010-09-07 : 15:07:48
|
consider those tables i said beforeassume that we have two users,so the users table must be like this:user_id user_name pwd 1 admin ....2 u1 ....3 u2 ....scenario 1: user "u1" wanna send message "hello u2" to user "u2"after sending email the mails table must be like this:mail_id sender reciever message1 u1 u2 hello u2scenario 2: admin of the site wanna send the message "hello everybody" to all usersafter that mails table must be like this:mail_id sender reciever message1 admin u1 hello everybody2 admin u2 hello everybodyis there a way that does not include using loop in application?****<< I Love MTN.SH >>**** |
 |
|
X002548
Not Just a Number
15586 Posts |
|
CSears
Starting Member
39 Posts |
Posted - 2010-09-07 : 16:24:03
|
Maybe you are looking for something like this?INSERT INTO MessageTable (Sender, Reciever, Message)SELECT 'Sender', UserName, 'Message' FROM UsersTable WHERE UserName in (Recipients) |
 |
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2010-09-07 : 16:35:30
|
quote: Originally posted by CSears Maybe you are looking for something like this?INSERT INTO MessageTable (Sender, Reciever, Message)SELECT 'Sender', UserName, 'Message' FROM UsersTable WHERE UserName in (Recipients)
YES . U THE MANthanks a lot, it's working****<< I Love MTN.SH >>**** |
 |
|
X002548
Not Just a Number
15586 Posts |
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2010-09-07 : 16:45:30
|
if u use a sqlCommand object in asp.net ,then after cmd.ExceuteNonQurery() method, it will return an int number which represents number of records affected****<< I Love MTN.SH >>**** |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-09-08 : 01:00:21
|
quote: Originally posted by mahdi87_gh if u use a sqlCommand object in asp.net ,then after cmd.ExceuteNonQurery() method, it will return an int number which represents number of records affected****<< I Love MTN.SH >>****
Salaam.But make sure you have set SET NOCOUNT OFF in your SP.With NOCOUNT ON the command object will always show the value as -1.Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
Sachin.Nand
2937 Posts |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
Sachin.Nand
2937 Posts |
Posted - 2010-09-08 : 01:49:27
|
Have a look at this.http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery(VS.71).aspxFor UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.So since the OP is using an INSERT statement setting it to OFF at SP level wont return anything to him by default.And also I just thought with @@ROWCOUNT and any other method it will need additional code in .net & also adding an additional output parameter in the SP.Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-09-08 : 10:28:59
|
quote: Originally posted by IderaDevelopers usually tend to set it to ON for better performance.
That might be .NET developers...I do know that in other languages, the the rows affected comes back as a result set...which is badI would be hesitant to change anything the way I code sprocs...There should be NO performance GAIN or LOSS by using an OUTPUT Variable that defines:- Number of Rows affected
- SQL Error Code
- Sproc User defined Error Code
- Sproc Defined Error Message
- Location of Error in the Sproc
MOOBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|