OT One for the msSQL experts - getting the database to do the work

I need a little advice on how to use either a function or
stored procedure
to handle some update work.
Basically I am building an application where customers are
assigned points
values based on the products that they have bought. In the
Orders table a
value is assigned to each order and I can get the total
points per customer
by running the following Select statement
SELECT Cust_ID, SUM(Order_Points) as PointsTotal
FROM tblOrders
WHERE Status_ID in (3,5,6)
GROUP BY Cust_ID
What I then want to do is the take the number for each
Customer and update
the value in a field called Cust_Points in tblCustomers.
I could simple write this to a dataset on the page, loop
through it and run
an update statement for each customer, but given that I am
using msSQL I am
sure that there is some way to write this whole action inside
of a stored
procedure or function and then just call that to handle the
work.
I am using ASP.Net C# for the pages.
Any help gratefully received.
Paul Whitham
Certified Dreamweaver MX2004 Professional
Adobe Community Expert - Dreamweaver
Valleybiz Internet Design
www.valleybiz.net

"Paul Whitham AdobeCommunityExpert"
<[email protected]> wrote in message
news:es8q3e$rle$[email protected]..
> I could simple write this to a dataset on the page, loop
through it and
> run an update statement for each customer, but given
that I am using msSQL
> I am sure that there is some way to write this whole
action inside of a
> stored procedure or function and then just call that to
handle the work.
Good instinct. :)
What you need in this case is a trigger.
You'll need to add an INSERT and/or UPDATE trigger to your
tblOrders table.
Which one you need (or if you need both) depends on your
workflow. I notice
you're only counting orders with certain status values. If an
order can be
inserted with one of those values, then you need an INSERT
trigger. If an
order gets one of those values on a later update, you need an
UPDATE
trigger. If either could be the case, you need both.
Your basic outline is:
INSERT trigger: if status is in (3,5,6) then add points to
tblCustomer.
UPDATE trigger: if status has changed from something other
than (3,5,6) and
is in (3,5,6), then add points to tblCustomer. If status has
changed from
something in (3,5,6) to something NOT in (3,5,6), then
subtract points from
tblCustomer. If status has not changed or does not change
"groups" (for
instance, was 3 becomes 5 or was 0 becomes 2), then do
nothing.
Here's some good resources on the basics of triggers in SQL
Server. These
should get you the knowledge you need. If you've got specific
questions
about the trigger afterward, then I'd suggest opening a new
thread just so
this one doesn't fall off.
Basics:
http://www.aspfree.com/c/a/MS-SQL-Server/Triggers/
That should be all you need this time around. Here's the rest
just for
completeness' sake:
Specifics:
http://www.aspfree.com/c/a/MS-SQL-Server/Trigger-Specifics/
Managing:
http://www.aspfree.com/c/a/MS-SQL-Server/Trigger-Management/

Similar Messages

  • One of the BizTalk Server processes in the affected computer is being throttled for significant periods because of high database size exceeding the threshold

    Hello Experts,
    I have complex Biz Talk 2013 farm having 20 servers,15 Hosts. In my production environment even if there is no traffic i am getting throttling errors from SCOM for my all the production hosts.
    Error : One of the BizTalk Server processes in the affected computer is being throttled for significant
    periods because of high database size exceeding the threshold
     I checked following things:
    1. MsgBoxDB size 748732 KB
    2. Spool table size  53 MB
    3. Tracking DB size 26724 KB
    4. Host settings --  Message Queue Size = 100, MsgCount = 50000 , Spool MP = 10 , Tracking MP = 10
    5. Ran Message Box viewer  and did not found any error related to DB size. (which counter i should focus on in MBV)
    Note -- for DB i am sharing full backup size because it does not have log file size.
    Please suggest where i should focus?
    Is SCOM reporting correctly because everything is fine in biztalk ?
    Thanks
    Yagya
    https://www.mcpvirtualbusinesscard.com/VBCServer/card.aspx?tag=YagyaDattMishra&wa=wsignin1.0

    Hi Yagyam
    I remember this error from SCOM when you use the standard SCOM BizTalk pack.
    Check the eventlog of the server, do you see any errors in event log, this could give some clue to the root cause. Whenever you have this alert from SCOM, you must have
    some entries in eventlog relating to the alert raised by SCOM.
    Is your message processing by BizTalk hosts are normal? Run the performance monitor to see the bottleneck. Check if there is really throttling.
    As mentioned in this blog, check the state of the SQL Agent on BizTalk's SQL database server, may be try restart the SQL Agent on BizTalk's SQL database server.
    http://blogs.msdn.com/b/timdel/archive/2008/11/19/why-i-love-scom.aspx
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Hi..I have an AirPort Extreme base connected to my DSL Modem and has been working fine. But I recently bought another DSL modem along with the latest Airport Express. With this one however I can't get it to connect to the Internet. Any suggestions?

    Hi..I have an AirPort Extreme base connected to my DSL Modem and has been working fine. But I recently bought another DSL modem along with the latest Airport Express. With this one however I can't get it to connect to the Internet. The light on the Express is flashing green though. Does it mean I have to re-set the settings on Airport Utility? I.e. the old settings haven't been cleared yet. Any suggestions?

    Let's see if I can get this straight.
    You have an Airport Extreme base station that is set to "Create a wireless network" and you have the box checked for "allow this network to be extended"....
    Then you have an Airport Express that is set to "Extend a wireless network" which you selected the name of your network in the box...
    Correct?
    See this Apple document:
    http://support.apple.com/kb/HT4259?viewlocale=en_US&locale=en_US
    The wireless unit on the right of the diagram can be either of the newer Apple base stations.
    Extreme, Express, Time Capsule

  • I uninstalled Firefox and not it will not install for me. I get a error that says, The item referred to by this shortcut cannot be accessed. You may not have the appropriate permissions. What can I do?

    I uninstalled Firefox and not it will not install for me. I get a error that says, The item referred to by this shortcut cannot be accessed. You may not have the appropriate permissions. What can I do?

    Here is a pic.

  • I've just upgraded to iPhone 4S and restored data from my old iPhone through iTunes.  I'm being asked for a password to get into my phone and the old password I had doesn't work.  I don't know what password it's looking for

    I've just upgraded to iPhone 4S and restored data from my old iPhone through iTunes.  I'm being asked for a password to get into my phone and the old password I had doesn't work.  I don't know what password it's looking for

    Thanks for replying, I'm a real techno-cretin.  What do you mean by not using the backup?  I'm busy trying to restore my new phone and it's doing a 6 hour download with updates.  Can I restore the data from my old phone backup onto the new iPhone 4S when the download is done?

  • I recently Updated my phone and my front camera stopped working its pitch black but still shows the icons on the screen but when i get off the app and get back on and flip the camera to my face view it works fine

    I recently Updated my phone and my front camera stopped working its pitch black but still shows the icons on the screen but when i get off the app and get back on and flip the camera to my face view it works fine

    Hi there Fgonzalez2015,
    You may find the camera troubleshooting steps in the article below helpful.
    Get help with the camera on your iPhone, iPad, or iPod touch
    You see a closed lens or black screen
    If you see a closed lens or black screen when you open the Camera app, try these steps:
    Make sure that there’s nothing blocking the camera lens. If you’re using a case, try removing it.
    Force the app to close, then open the Camera app again.
    Restart your device, then open the Camera app again.
    If your device has a front and rear camera, try both cameras by tapping the camera swap icon . If you see the closed lens or black screen on only one camera, take your device to an Apple Retail Store or Authorized Service Provider for more help.
    -Griff W.  

  • Hi guys....When I am sending an ical invitation, the recipient is getting it an hour of the invited time.

    Hi guys....When I am sending an ical invitation, the recipient is getting it an hour of the invited time. I have checked the time is correct on my Macbook Pro and the time zone is set for where I am? Can anyone help please

    Welcome to Apple Communities
    You have an issue with your router. Try another one, connect it by Ethernet if you use Wi-Fi or take your Mac to an Apple Store

  • I'm really tired of all the redirect I get when I'm surfing the net. i've set in the option to warn when trying to redirect

    I'm really tired of all the redirect I get when I'm surfing the net. i've set in the option to warn when trying to redirect

    If you are being re-directed to other sites, particularly when searching, this can be caused by malware. Try running several malware scanners. It is best to run several as each will pick up things that the others miss. Some scanners you can try are:
    * [http://www.malwarebytes.org/mbam.php Malwarebytes]
    * [http://www.superantispyware.com/ SUPERAntiSpyware]
    * [http://www.lavasoft.com/products/ad_aware_free.php Ad-Aware]
    * [http://www.microsoft.com/windows/products/winfamily/defender/default.mspx Windows Defender]
    * [http://www.safer-networking.org/en/home/index.html Spybot S&D]
    If the above malware scanners do not find any malware or can not clear it, you should consider posting in one of these forums for specialized malware removal help:
    * http://forums.spybot.info/
    * http://www.spywarewarrior.com/index.php
    * http://forum.aumha.org/
    * http://www.bleepingcomputer.com/forums/
    * http://www.spywareinfoforum.com/

  • Firefox browser keeps going into not responding mode and the firefox experts continue to "not respond" to the problem. Firefox 11.0 and W7.

    Firefox browser keeps going into not responding mode and the firefox experts continue to "not respond" to the problem. Firefox 11.0 and W7. When will you respond??

    Try to start Firefox in [[Safe mode|Safe mode]]. This mode disables all extensions, user customizations, hardware acceleration, etc. temporarily for diagnostic and troubleshooting. If Firefox works find in Safe Mode, then this is likely an add-on issue. Restart Firefox in normal mode, then type "About:addons" (without the quotes) in the address bar. Disable your extensions one by one, restarting Firefox between each one, until you find the trouble maker. Once you do, you can disable that add-on and report the issue to that add-on's developer.
    A few other basic trouble shooting things you can try is this:
    Run all Windows Updates, install all needed service packs, etc.
    Update your graphics driver (Firefox uses your graphics card for some rendering, and an out of date graphics card driver can cause problems. [https://support.mozilla.org/en-US/kb/how-do-i-upgrade-my-graphics-drivers https://support.mozilla.org/en-US/kb/how-do-i-upgrade-my-graphics-drivers].
    Update all your plugins (Flash, Java, etc.): [http://www.mozilla.org/plugincheck/ http://www.mozilla.org/plugincheck/].
    Download and Install MalwareBytes Anti-Malware, run a full Scan. [http://www.malwarebytes.org/ http://www.malwarebytes.org/]. This helps check that there are no viruses on your computer causing issues. you can uninstall this program after you clean off any infections.
    Now when Firefox hangs, is this randomly, on specific websites, etc.? You can also read [https://support.mozilla.org/en-US/kb/Firefox-hangs https://support.mozilla.org/en-US/kb/Firefox-hangs]

  • Next upcoming expert day Looking forward to the next Expert Day any estimated date of the event

    next upcoming expert day Looking forward to the next Expert Day any estimated date of the event
    it‘s great to be able to post in the forum and obtain help
    my gratitude and appreciation is certainly provided; may I inquire
    as to any estimate Is there another
    Upcoming Expert Day Event
    Since the designated Expert Day is stated as the event has now concluded for
    Expert Day in English (Consumer) - April 18-19, 2012
    Hopefully before September
    Thanks  
    Respectfully

    However if it is Sep I’ll gladly wait and that is still excellent the designated Expert Day’s are great
    my gratitude and appreciation is certainly provided..

  • I have a big crossbar mark over my FF4 icon after I've installed and replaced FF3. When I try to open the software, I get "You can't open the application "Firefox" because it is not supported on this architecture." What's up with that?

    I have a big crossbar mark over my FF4 icon after I've installed and replaced FF3. When I try to open the software, I get "You can't open the application "Firefox" because it is not supported on this architecture." What's up with that?

    Firefox 4 requires at least OS X 10.5 and an Intel Mac. There is a third party version of Firefox 4 that runs on OS X 10.4/10.5 and PPC Macs, for details see http://www.floodgap.com/software/tenfourfox
    If you prefer, you can get the latest version of Firefox 3.6 from http://www.mozilla.com/en-US/firefox/all-older.html

  • When I take my phone off charge in the morning I get an info box on the front which has the sound trumpet icon with a line through it and the word Mute.  The only way to get rid of it is to reboot the phone any ideas as to how I can stop this happening?

    When I take my phone off charge in the morning I get an info box on the front which has the sound trumpet icon with a line through it and the word Mute.  The only way to get rid of it is to reboot the phone any ideas as to how I can stop this happening?

    Hello cor-el, thanks for your reply. I changed my settings for downloads to desktop and it has appeared on there. When I double click I am asked which program I want to open file. I click firefox and another box "opening install" says I have chosen to open the file which is an application and do I want to save it. This is the only real option so I press save file. I get a box saying this is an executable file which may contain viruses - do you want to run. I press ok and the final box showing C drive file name and desktop appears stating application not found.
    This happens the same whenever I try to install.
    To my untrained eye the application is not being recognised as an application and I cannot work out how to get it to do that.
    My plugin is still showing as out of date.
    Is there anything you could suggest. Thanks for your time.

  • HT3964 I am not able to reboot my Mac desktop. When I switch on the Mac, I get a white screen with the Apple logo and the little wheel below that goes round and round but the computer refuses to boot.

    Hi, I am not able to reboot my Mac desktop.
    When I switch on the Mac, I get a white screen with the Apple logo and the little rotating circle.
    The system refuses to boot.
    What can I do?
    Marcus

    We need to get you moved. This forum is for mini-tower Macs built between 1998 and 2005 and doesn;t get as much traffic ("eyeballs on the problem") as the forums for newer Macs.
    Please do "About this Mac" from you Apple menu and tell us what that says for "processor" and Mac OS version. Looks like this:
    or this for later Mac OS versions:
    With that we can figure out which of the two iMac forums you need and get the Hosts to move your post.

  • I cannot activate the screen saver. My operating system is Mac OS X version 10.6.8. The screen message says 'Please contact the vendor to get a newer version of the screen saver'

    When I try and activate my screen saver the following message appears
    Please contact the vendor to get a newer version of the screen saver
    My operating system is Mac OS X  version 10.6.8

    To begin with, you have the wrong forum - the iMacs covered by this forum were discontinued in 2005 and are incapable of running OS X 10.6.x
    Try either iMac (Intel) or Snow Leopard forums.
    To get more help, contributors will need to know what screensaver you're trying to use - is it one downloaded from the internet or one of the OS X default set?

  • I have problem with my iphone 5 when I talk my ear allways tuch the screen and get it on no sound, the screen are not lock, is that possible

    I have problem with my Iphone 5, when I talk my ear allways tuch the screen and get it on no sound, the screen are not lock, is ti possible to lock the screen when incomming an outgoing call going on

    Hello Mogulman46,
    So what that means is when you have Do Not Disturb turned on, you may have an alert depending on the setting and how you are using your iPhone. So if it is set to Always, then that means that no matter what, your iPhone will not be notified. If it set to Only while the iPhone is locked, then that means that you will not get notification when your iPhone is locked but you will get notifications if your iPhone is being used. Also keep in mind the settings All Calls From can be set to certain contacts like Favorites, Everyone or no one. If you are using Do Not Disturb and you do not need it, then turn it off. 
    Use Do Not Disturb on your iPhone, iPad, or iPod touch
    http://support.apple.com/kb/ht5463
    Regards,
    -Norm G. 

Maybe you are looking for