Solved

SQL question; ExecuteScale

Posted on 2013-01-04
5
255 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
  • 2
  • 2
5 Comments
 
LVL 42

Expert Comment

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

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

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 26

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now