Solved

SQL question; ExecuteScale

Posted on 2013-01-04
5
262 Views
Last Modified: 2013-01-10
I have this compound SQL statement that I execute using ExecuteScaler.

UPDATE IHPS_case_note SET safety_plan_revision_request = 'xxxxxxxx' FROM IHPS_case_note INNER JOIN ihps_case ON ihps_case.ID = ihps_case_note.fk_caseID INNER JOIN ihps_create_log ON ihps_create_log.ID = ihps_case.FK_createlogID WHERE DHS_evaluationID = '341287' AND ihps_create_log.incremental = 1;

SELECT IHPS_case_note.ID from IHPS_case_note INNER JOIN ihps_case ON ihps_case.ID = ihps_case_note.fk_caseID INNER JOIN ihps_create_log ON ihps_create_log.ID = ihps_case.FK_createlogID WHERE DHS_evaluationID = '341287' AND ihps_create_log.incremental = 1

This works fine, as it returns the Primary Key of the record that I just updated.  Is there a better way to do this, without duplicating the whole UPDATE SQL statement?
0
Comment
Question by:HLRosenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 43

Expert Comment

by:Eugene Z
ID: 38746086
could you please clarify your question and why do you nee to use ExecuteScaler

BTW: did you mean .Net ExecuteScaler?
0
 
LVL 27

Expert Comment

by:Chris Luttrell
ID: 38746223
Try this, I know it works in T-SQL in a query window, I believe it will work from being called from .Net as well.  The OUTPUT clause will return values from the INSERTED Psudo table just like you use in triggers.
UPDATE IHPS_case_note SET safety_plan_revision_request = 'xxxxxxxx' 
OUTPUT INSERTED.ID
FROM IHPS_case_note INNER JOIN ihps_case ON ihps_case.ID = ihps_case_note.fk_caseID INNER JOIN ihps_create_log ON ihps_create_log.ID = ihps_case.FK_createlogID WHERE DHS_evaluationID = '341287' AND ihps_create_log.incremental = 1;

Open in new window

0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 38750838
I not sure that I need ExecuteScaler.   What I want is the simpliest way to return back the Primary Key of the record that I updated.
0
 
LVL 27

Accepted Solution

by:
Chris Luttrell earned 500 total points
ID: 38751036
Did you try the OUTPUT clause yet?  Did it not work?
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 38763935
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question