473,416 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Stored procedure SQL issue

132 100+
Hi there.

Within my stored procedure I have a piece of SQL that is supposed to remove from a temporary table, any values that are not set to '1' for a particular field, but this does not work as required.

The SQL in question looks like this:

Expand|Select|Wrap|Line Numbers
  1. DELETE FROM table1
  2. WHERE value_1 NOT IN
  3. (
  4.     SELECT tab1.value_1
  5.     FROM table1 tab1
  6.  
  7.     JOIN table2 tab2 ON tab1.value_1 = tab2.value_1 AND tab1.line_no = tab2.line_no
  8.     AND tab1.client = tab2.client
  9.  
  10.     JOIN table3 tab3 ON tab3.client = tab2.client 
  11.     AND tab3.THIS_VALUE = 1 AND tab3.value_2 = tab2.value_2
  12.  
  13.     JOIN table4 tab4 ON tab3.client = tab4.client AND tab3.value_3 = tab4.tab4_value
  14.  
  15.     JOIN table5 tab5 ON tab5.client = tab4.client AND tab5.art_id = tab4.art_id
  16.     AND tab5.Sub_id = @SubID AND tab5.Seq_no = @SeqNo
  17.     AND tab1.client = @Client
  18. )
  19.  
Can you see what I have done wrong here please, as the test for tab3.THIS_VALUE = 1 is returbning results for THIS_VALUE = 0 also.

Thank you.
Oct 13 '10 #1
4 1037
ck9663
2,878 Expert 2GB
Before we proceed, are you sure the temp table is accessible by the above mentioned query?

~~ CK
Oct 13 '10 #2
E11esar
132 100+
Hi there.

Yes the table is accessible and is created earlier on within the stored procedure.

Thank you.
Oct 13 '10 #3
ck9663
2,878 Expert 2GB
And when you run your sub-query, there are results that return?

~~ CK
Oct 13 '10 #4
NeoPa
32,556 Expert Mod 16PB
E11esar, it seems your description of your problem doesn't match the SQL that you've posted. The question implies the value should 1 to be deleted. Furthermore, if you need telling that the data returned from your subquery will be necessary to help resolve this then here we go. It will be. We don't know what's in your tables, or even how they're structured. It will be necessary to post the data at least.

Please take more care in future to post a full and clear question in your first post. I'd have thought you'd been with us long enough to understand that by now.
Oct 14 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Thomas R. Hummel | last post by:
I have a stored procedure that suddenly started performing horribly. The query plan didn't look right to me, so I copy/pasted the code and ran it (it's a single SELECT statement). That ran pretty...
10
by: Sam | last post by:
Hi, The following does not work, it doesn't seem to like a stored procedure combined with a sql request. Why and how can I overcome this ? SELECT table_name from INFORMATION_SCHEMA.tables...
2
by: James Foreman | last post by:
I'm building a stored procedure that simulates cars arriving in a car park, and staying for different amounts of time, based on historical data. So, first I define a cursor that's populated by...
2
by: Praveen_db2 | last post by:
Hi All db2 V 8.1.3 Windows I have an application which processes some rows using an SP.There are 2 approaches to this issue. 1) I can call the SP once and pass all the rows together as CLOB.(Rows...
2
by: Dave Anderson | last post by:
I really like Bob's "stored procedure as method of Connection Object" technique. It is convenient, compact, and concise, and simplifies protection from SQL injection. HOWEVER, I cannot figure...
5
by: James Wong | last post by:
Hi, I am writing a vb.net2005 program that needs to create a stored procedure with SqlServerProject Template. Now, I have two questions for this stored procedure. 1) How can I import and...
3
by: pinney.colton | last post by:
I would like to create a stored procedure which creates a temp table to store some XML. The # of fields of XML is dependent upon the contents of another table in the application, so the first part...
0
by: mraikundalia | last post by:
I have multiple Playerid.. (1 to 37) how can i incorperate this into the stored procedure.. I could hard code all 37 but when an increase is players i would have to modify every single time. Below...
5
by: william.david.anderson | last post by:
Hi there, I have a newbie question regarding stored procedures and locking. I'm trying to use a stored procedure to perform a 'select for update' and return a cursor. Below is a stripped down...
0
by: piperdawn | last post by:
Hi Guys, We have a requirement wherein when the value in the column of a particular DB2 table changes to a certain value, a job must be triggered which will execute a program and generate a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.