|
-
Apr 4th, 2005, 07:58 AM
#1
Thread Starter
New Member
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
-
Apr 4th, 2005, 08:23 AM
#2
Hyperactive Member
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..
-
Apr 4th, 2005, 08:38 AM
#3
Thread Starter
New Member
Re: This has got me puzzled... Executed SQL Query
Hi,
The returned value is not null, that's why I'm really lost.
-
Apr 4th, 2005, 08:46 AM
#4
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?
-
Apr 4th, 2005, 08:47 AM
#5
Hyperactive Member
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.
-
Apr 4th, 2005, 08:48 AM
#6
Re: This has got me puzzled... Executed SQL Query
 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...
-
Apr 4th, 2005, 09:27 AM
#7
Thread Starter
New Member
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
-
Apr 4th, 2005, 09:29 AM
#8
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)
-
Apr 4th, 2005, 09:47 AM
#9
Need-a-life Member
Re: This has got me puzzled... Executed SQL Query
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|