Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:49:53+00:00 2026-06-10T06:49:53+00:00

Assume this script: DECLARE @result TABLE(Id BIGINT); DELETE FROM [Products].[Product] OUTPUT DELETED.[Id] INTO @result

  • 0

Assume this script:

DECLARE @result TABLE(Id BIGINT);

DELETE FROM [Products].[Product]
OUTPUT DELETED.[Id] INTO @result
WHERE [Products].[Product].[Id] = 1589;

So in continues I try :

1

SELECT CAST(ISNULL([Id], -1) AS BIGINT) AS N'RetValId' FROM @result;

When [Id] is null returned null (nothing), but this one returned -1:

2

DECLARE @mi BIGINT;
SET @mi = (SELECT [Id] FROM @result)
SELECT CAST(ISNULL(@mi, -1) AS BIGINT) AS N'RetValId'

Why? where is the problem with first script?

Update

So is there any way to check if the Deleted Id is null returned -1 And if not Returned Id without declare another variable? what is the simplest way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:49:54+00:00Added an answer on June 10, 2026 at 6:49 am

    If you have no entry for the ID 1589, then in the DELETED table there will be no record, if you have it then it should return 1589.

    So if you don’t have I think it simple returns nothing, because this statement has no input row:

    SELECT CAST(ISNULL([Id], -1) AS BIGINT) AS N'RetValId' FROM @result;
    

    (If you SELECT * from @result it should be no rows there)

    The second one return the -1 because you set first to the variable which is getting the NULL value after the select.

    DECLARE @mi BIGINT;
    SET @mi = (SELECT [Id] FROM @result)
    

    (If you select only @mi after this, then it should be NULL)

    I think that is the explanation

    UPDATED:

    May you can try a small trick to achive it without an other varriable:

    SELECT CAST(ISNULL(MAX([ID]),-1) AS BIGINT) AS N'RetValId' FROM @result;
    

    Because of MAX the insie statement will be NULL, so here is the trick. If something was deleted, then the ID will be there.
    I hope it helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this script, I'm fetching a load of data from a MySQL aray, and
I assume this script calls itself everytime with the .call(this) function which explains why
Assume this code works: left '*' left '+' expr: expr '+' expr | expr
assume this following function: int binaryTree::findHeight(node *n) { if (n == NULL) { return
I assume this is an IIS error, as this doesn't happen if I run
I assume this is really easy, and I'm missing something obvious. I'm connecting to
I assume this should be fine bool prefMatch = false; // Is the frequency
I assume this just returns an int. Is there anything else going on I
Let's assume this scenario in Visual C++ 2010: #include <iostream> using namespace std; struct
Let's assume this class in C#: public class LimitedList<T> : List<T> { private int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.