Results 1 to 13 of 13
  1. #1
    Join Date
    May 2013
    Posts
    8

    Unanswered: Process filtered set of records

    I have a table in SQL 2012 where we add records on daily bases.
    A col is for user name.

    I want to select records with each user and send the same to that user with db mail.

    I have worked with VB but
    I am totally new in this field.

    Any help is appreciated.

    Regards,
    Spareus.

  2. #2
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Use either a dts or ssis package for this type of work.

  3. #3
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    You are going to want to create a CURSOR ( DECLARE CURSOR (Transact-SQL) ) with the result set from your table and inside that CURSOR you are going to want to execute sp_send_dbmail (sp_send_dbmail (Transact-SQL)). This is assuming DBMail is configured on your server.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  4. #4
    Join Date
    May 2013
    Posts
    8
    Can you please elaborate.
    If you can explain how to do it, it will be helpful.

    Regards,

  5. #5
    Join Date
    May 2013
    Posts
    8
    Thrasymachus,
    Thanks.
    Is it possible for you to provide an example?

    Thanks again.

  6. #6
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    If you combine the examples in the two links I already provided, you may find your solution. Why don't you try that, and if you have a problem or an error with it, come back here and ask specific questions.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  7. #7
    Join Date
    May 2013
    Posts
    8
    Thrasymachus,
    Sorry. I mistook your links with highlighted words.
    I have gone thru the curser.
    I found that cursers return each record one by one. This is not required.
    I want to process set of filtered records.
    Say,
    when we work in excel, I apply filter on a username, user1 which will show 10 records.
    Send those 10 records to user1.
    Now againn, set filter on user2 which will show n records.
    Send those n records to user 2
    and so on for each user.

    Hope I have clarified properly.
    Pl help.
    Regards.

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    If you know Excel, then process the data there.

    You can manually cut-and-paste the data from a query window, or you can create an external query within Excel to populate a worksheet and then process the results of that query using the familiar Excel tools.

    This would be a lot easier than learning to use SQL Server for just one task!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  9. #9
    Join Date
    May 2013
    Posts
    8
    I know Excel, but I have only given example to explain my requirement.
    Since there will be lot many users, I can not do cut paste.
    I have to loop thru all users and mail them their data ( each user will have more then 1 row).
    Pl help me.

    Regards,

  10. #10
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Excel can handle many thousands of rows. SQL Server is a relatively complex and powerful tool. It isn't worth learning to use SQL Server to process a single mail merge, regardless of the size of that task.

    What version of Excel are you running?

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  11. #11
    Join Date
    May 2013
    Posts
    8
    I am having Excel 2007. It can handle 1048576 rows max.
    My data is having 65410116 records and adding daily. It will send mail to few hundred users with their records.

    Regards,

  12. #12
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Assuming that a "few hundred" means less than a thousand, your average user will get more than 65000 rows of data? You already have a much larger problem than the SQL Server issue!

    I'm sorry, I can't help you resolve that but I'll be interested to see how it turns out!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  13. #13
    Join Date
    May 2013
    Posts
    8
    Its not that way. I will be using query to filterout required data.
    Average user will get anything between 200 to 800 rows.
    New users will be added and some users will be removed on weekly basis.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •