Results 1 to 9 of 9

Thread: This has got me puzzled... Executed SQL Query RESOLVED

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    3

    Exclamation This has got me puzzled... Executed SQL Query RESOLVED

    Hi everyone,

    I have an SQL query that I am executing in my program. The query doesn't work in the application, but works when executed by itself using SQL Query Analyser.

    Here is the query :

    strSQL = "UPDATE Stock_Details SET SDInputDate = (SELECT SDInputDate FROM Stock_Details WHERE ObjectID = 4887) WHERE ObjectID = 504"

    If I execute this query in the application, it says that "SELECT SDInputDate FROM Stock_Details WHERE ObjectID = 4887" returns a NULL value, and it cannot perform the update since the table doesn't allow nulls in the column i'm updating.

    But, if I execute it in SQL Query Analyser, the query works perfectly fine, and no NULL values are returned.

    I am completely puzzled, and I have been toying with this for the last 2 days.

    Any tips ?

    Thanks!
    Last edited by hkhalil; Apr 4th, 2005 at 09:27 AM. Reason: resolved

  2. #2
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    308

    Re: This has got me puzzled... Executed SQL Query

    What comes back from the DB if you simply use the inner select (SELECT SDInputDate FROM Stock_Details WHERE ObjectID = 4887) as the SQL source ?? Is it Null???

    Chub..

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    3

    Re: This has got me puzzled... Executed SQL Query

    Hi,

    The returned value is not null, that's why I'm really lost.

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: This has got me puzzled... Executed SQL Query

    What you have is a totally legitimate query, I just tried something like it in QA myself and it worked just fine.

    You must be typing something wrong or have something very silly going on.

    Can you post the actual code / copy+paste it into a [CODE] tagged block in the forum here?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    308

    Re: This has got me puzzled... Executed SQL Query

    What putting a query something like this into the String and executing it ? (Check the syntax as this is done without checking).

    Code:
    --- Not quite sure if you need this line but put it in anyway.
    SET NOCOUNT ON
    
    DECLARE @SDInputDate Integer
    
    SET @SDInputDate = SELECT SDInputDate FROM Stock_Details WHERE ObjectID = 4887
    
    --- Switch it Off
    SET NOCOUNT OFF
    
    UPDATE Stock_Details SET SDInputDate = @SDInputDate WHERE ObjectID = 504

    Chubby.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: This has got me puzzled... Executed SQL Query

    Quote Originally Posted by hkhalil
    If I execute this query in the application, it says that "SELECT SDInputDate FROM Stock_Details WHERE ObjectID = 4887" returns a NULL value, and it cannot perform the update since the table doesn't allow nulls in the column i'm updating.
    How are you getting it to say an error message like this?

    It would not give you a message about 4887, but about the column not accepting nulls...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    3

    Re: This has got me puzzled... Executed SQL Query

    Sorry guys, I forgot something very silly in the code. Everything works now so it's all good

    Thanks again, and sorry for the trouble

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: This has got me puzzled... Executed SQL Query RESOLVED

    I'm glad it worked out - must have been a psychic moment for me (or typo's are just that common)

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: This has got me puzzled... Executed SQL Query

    Quote Originally Posted by hkhalil
    Sorry guys, I forgot something very silly in the code. Everything works now so it's all good

    Thanks again, and sorry for the trouble
    Care to share with all of us?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

Posting Permissions

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



Click Here to Expand Forum to Full Width