473,769 Members | 5,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting few Recordsets into Temp Table containing NULL Values

Hi
I need some help on achieving the following:

I wrote a querie which collects Data out of three Tables, the Result
looks like this:

SET NOCOUNT ON

DECLARE @ROW INT

DECLARE @CURPTNO CURSOR

SET @CURPTNO = CURSOR
FOR
SELECT * FROM TEMP

OPEN @CURPTNO

FETCH NEXT FROM @CURPTNO
INTO @ROW

WHILE (@@FETCH_STATUS = 0)

BEGIN

SELECT ONE.CYNO, ONE.ROLE, ONE.ROL_BEZ, ONE.PTNO, ONE.NOCY, TWO.TEXT
AS NOCY_TEXT
FROM
(SELECT CY.CYNO,
RE.CYNO AS RECYNO, RTRIM(RE.ROLE) AS ROLE, RTRIM(V_ROLE.TE XT) AS
ROL_BEZ,
RE.PTNO AS PTNO, RTRIM(RE.NAME) AS SACHBEARBEITER, RE.NOCY
FROM CY
RIGHT OUTER JOIN
RE ON RE.CYNO = CY.CYNO
INNER JOIN
V_ROLE ON RE.ROLE = V_ROLE.CODE
WHERE (RE.PTNO IN
(SELECT PT.PTNO
FROM PT
WHERE PT.PTNO IN
(@ROW)
AND V_ROLE.LANGUAGE = PT.CLANG
))) AS ONE

LEFT JOIN

(SELECT V_NOCY.CODE, V_NOCY.TEXT
FROM V_NOCY
INNER JOIN
PT ON PT.CLANG = V_NOCY.LANGUAGE
AND PT.PTNO IN (SELECT PT.PTNO
FROM PT
WHERE PT.PTNO IN
(@ROW)
)) AS TWO
ON ONE.NOCY = TWO.CODE

FETCH NEXT FROM @CURPTNO
INTO @ROW

END

CLOSE @CURPTNO

DEALLOCATE @CURPTNO

The Result looks like this:
RS1:
6313,1300,Archi tekt,99737505,N ULL,NULL
2392762,100,Bau herr,99737505,N ULL,NULL

RS2:
2693265,100,Bau herr,99756900,N ULL,NULL
NULL,1,Planer,9 9756900,2,Bauhe rr macht Pläne selber

RS3:
2691919,100,Bau herr,99755058,N ULL,NULL
2691962,6000,Ko ntakt,99755058, NULL,NULL

My Problem is, that I need to have all the Resultsets in one Table at
the end.
So my further undertaking was to create a Temp Table with the
expectation to receive all the resultsets in one Step.

The TSQL for this looks like that:

SET NOCOUNT ON

CREATE TABLE #CYRE_TEMP
( CYNO INT NULL,

ROLE INT NULL,
ROL_BEZ VARCHAR (60) NULL,
PTNO INT NULL ,
NOCY INT NULL,
TEXT VARCHAR (60) NULL
)

GO

DECLARE @CYNO INT,

@ROLE INT,
@ROL_BEZ VARCHAR (60),
@PTNO INT,
@NOCY INT,
@TEXT VARCHAR (60),
@ROW INT,
@CURPTNO CURSOR

SET @CURPTNO = CURSOR FOR
SELECT PTNO FROM TEMP

OPEN @CURPTNO

FETCH NEXT FROM @CURPTNO
INTO @ROW

WHILE (@@FETCH_STATUS = 0)

BEGIN

INSERT INTO #CYRE_TEMP (CYNO, ROLE, ROL_BEZ, PTNO, NOCY, TEXT)

VALUES

(@CYNO,@ROLE ,@ROL_BEZ ,@PTNO ,@NOCY ,@TEXT)

SELECT @CYNO = ONE.CYNO,

@ROLE = ONE.ROLE,
@ROL_BEZ = ONE.ROL_BEZ,
@PTNO = ONE.PTNO,
@NOCY = ONE.NOCY,
@TEXT = TWO.TEXT
FROM
(SELECT CY.CYNO, RTRIM(RE.ROLE) AS ROLE, RTRIM(V_ROLE.TE XT) AS
ROL_BEZ,
RE.PTNO AS PTNO, RTRIM(RE.NAME) AS SACHBEARBEITER, RE.NOCY
FROM CY
RIGHT OUTER JOIN
RE ON RE.CYNO = CY.CYNO
INNER JOIN
V_ROLE ON RE.ROLE = V_ROLE.CODE
WHERE (RE.PTNO IN
(SELECT PT.PTNO
FROM PT
WHERE PT.PTNO =
@ROW
AND V_ROLE.LANGUAGE = PT.CLANG
))) AS ONE

LEFT JOIN

(SELECT V_NOCY.CODE, V_NOCY.TEXT
FROM V_NOCY
INNER JOIN
PT ON PT.CLANG = V_NOCY.LANGUAGE
AND PT.PTNO IN (SELECT PT.PTNO
FROM PT
WHERE PT.PTNO =
@ROW
)) AS TWO
ON ONE.NOCY = TWO.CODE

FETCH NEXT FROM @CURPTNO
INTO @ROW
END

CLOSE @CURPTNO
DEALLOCATE @CURPTNO

SELECT * FROM #CYRE_TEMP

DROP TABLE #CYRE_TEMP

GO

And the Output looks like this now:

Q1:
NULL,NULL,NULL, NULL,NULL,NULL
2392762,100,Bau herr,99737505,N ULL,NULL
NULL,1,Planer,9 9756900,2,Bauhe rr macht Pläne selber
Can someone help me getting all the 6 Rows into one Table as Output?

I appreciate any available Help on this..

Ssscha
Jul 20 '05 #1
1 2716
Hi

Posting DDL (CREATE TABLE statements etc.) Example Data (As Insert
Statements) helps when trying to answer questions like this. Without
testing(!) this may go some way to solving the problem.

SELECT CY.CYNO, RTRIM(RE.ROLE) AS ROLE, ONE.ROL_BEZ, RE.PTNO, RE.NOCY,
V_NOCY.TEXT AS NOCY_TEXT
FROM RE
INNER JOIN V_ROLE ON RE.ROLE = V_ROLE.CODE
INNER JOIN PT ON RE.PTNO = PT.PTNO AND V_ROLE.LANGUAGE = PT.CLANG
INNER JOIN #TEMP T ON PT.PTNO = T.PTNO
INNER JOIN V_NOCY ON V_NOCY.CODE = RE.NOCY
INNER JOIN PT ON PT.CLANG = V_NOCY.LANGUAGE
LEFT OUTER JOIN CY ON RE.CYNO = CY.CYNO

John

"Sascha" <sa************ ****@fachmediac om.ch> wrote in message
news:3d******** *************** ***@posting.goo gle.com...
Hi
I need some help on achieving the following:

I wrote a querie which collects Data out of three Tables, the Result
looks like this:

SET NOCOUNT ON

DECLARE @ROW INT

DECLARE @CURPTNO CURSOR

SET @CURPTNO = CURSOR
FOR
SELECT * FROM TEMP

OPEN @CURPTNO

FETCH NEXT FROM @CURPTNO
INTO @ROW

WHILE (@@FETCH_STATUS = 0)

BEGIN

SELECT ONE.CYNO, ONE.ROLE, ONE.ROL_BEZ, ONE.PTNO, ONE.NOCY, TWO.TEXT
AS NOCY_TEXT
FROM
(SELECT CY.CYNO,
RE.CYNO AS RECYNO, RTRIM(RE.ROLE) AS ROLE, RTRIM(V_ROLE.TE XT) AS
ROL_BEZ,
RE.PTNO AS PTNO, RTRIM(RE.NAME) AS SACHBEARBEITER, RE.NOCY
FROM CY
RIGHT OUTER JOIN
RE ON RE.CYNO = CY.CYNO
INNER JOIN
V_ROLE ON RE.ROLE = V_ROLE.CODE
WHERE (RE.PTNO IN
(SELECT PT.PTNO
FROM PT
WHERE PT.PTNO IN
(@ROW)
AND V_ROLE.LANGUAGE = PT.CLANG
))) AS ONE

LEFT JOIN

(SELECT V_NOCY.CODE, V_NOCY.TEXT
FROM V_NOCY
INNER JOIN
PT ON PT.CLANG = V_NOCY.LANGUAGE
AND PT.PTNO IN (SELECT PT.PTNO
FROM PT
WHERE PT.PTNO IN
(@ROW)
)) AS TWO
ON ONE.NOCY = TWO.CODE

FETCH NEXT FROM @CURPTNO
INTO @ROW

END

CLOSE @CURPTNO

DEALLOCATE @CURPTNO

The Result looks like this:
RS1:
6313,1300,Archi tekt,99737505,N ULL,NULL
2392762,100,Bau herr,99737505,N ULL,NULL

RS2:
2693265,100,Bau herr,99756900,N ULL,NULL
NULL,1,Planer,9 9756900,2,Bauhe rr macht Pläne selber

RS3:
2691919,100,Bau herr,99755058,N ULL,NULL
2691962,6000,Ko ntakt,99755058, NULL,NULL

My Problem is, that I need to have all the Resultsets in one Table at
the end.
So my further undertaking was to create a Temp Table with the
expectation to receive all the resultsets in one Step.

The TSQL for this looks like that:

SET NOCOUNT ON

CREATE TABLE #CYRE_TEMP
( CYNO INT NULL,

ROLE INT NULL,
ROL_BEZ VARCHAR (60) NULL,
PTNO INT NULL ,
NOCY INT NULL,
TEXT VARCHAR (60) NULL
)

GO

DECLARE @CYNO INT,

@ROLE INT,
@ROL_BEZ VARCHAR (60),
@PTNO INT,
@NOCY INT,
@TEXT VARCHAR (60),
@ROW INT,
@CURPTNO CURSOR

SET @CURPTNO = CURSOR FOR
SELECT PTNO FROM TEMP

OPEN @CURPTNO

FETCH NEXT FROM @CURPTNO
INTO @ROW

WHILE (@@FETCH_STATUS = 0)

BEGIN

INSERT INTO #CYRE_TEMP (CYNO, ROLE, ROL_BEZ, PTNO, NOCY, TEXT)

VALUES

(@CYNO,@ROLE ,@ROL_BEZ ,@PTNO ,@NOCY ,@TEXT)

SELECT @CYNO = ONE.CYNO,

@ROLE = ONE.ROLE,
@ROL_BEZ = ONE.ROL_BEZ,
@PTNO = ONE.PTNO,
@NOCY = ONE.NOCY,
@TEXT = TWO.TEXT
FROM
(SELECT CY.CYNO, RTRIM(RE.ROLE) AS ROLE, RTRIM(V_ROLE.TE XT) AS
ROL_BEZ,
RE.PTNO AS PTNO, RTRIM(RE.NAME) AS SACHBEARBEITER, RE.NOCY
FROM CY
RIGHT OUTER JOIN
RE ON RE.CYNO = CY.CYNO
INNER JOIN
V_ROLE ON RE.ROLE = V_ROLE.CODE
WHERE (RE.PTNO IN
(SELECT PT.PTNO
FROM PT
WHERE PT.PTNO =
@ROW
AND V_ROLE.LANGUAGE = PT.CLANG
))) AS ONE

LEFT JOIN

(SELECT V_NOCY.CODE, V_NOCY.TEXT
FROM V_NOCY
INNER JOIN
PT ON PT.CLANG = V_NOCY.LANGUAGE
AND PT.PTNO IN (SELECT PT.PTNO
FROM PT
WHERE PT.PTNO =
@ROW
)) AS TWO
ON ONE.NOCY = TWO.CODE

FETCH NEXT FROM @CURPTNO
INTO @ROW
END

CLOSE @CURPTNO
DEALLOCATE @CURPTNO

SELECT * FROM #CYRE_TEMP

DROP TABLE #CYRE_TEMP

GO

And the Output looks like this now:

Q1:
NULL,NULL,NULL, NULL,NULL,NULL
2392762,100,Bau herr,99737505,N ULL,NULL
NULL,1,Planer,9 9756900,2,Bauhe rr macht Pläne selber
Can someone help me getting all the 6 Rows into one Table as Output?

I appreciate any available Help on this..

Ssscha

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5357
by: R. Santiago | last post by:
I have a table cc_rd_user_questions with the following columns: NUM NUMBER (25) DEFAULT 1 NOT NULL, COMPANY_ID NUMBER (15) NOT NULL, PROJ_ID NUMBER (15) NOT NULL, SEQ NUMBER (25) NOT NULL, QUEST_ID NUMBER (15) NOT NULL, RESPONSE VARCHAR2 (40), CREATE_DATE DATE NOT NULL, LAST_UPDATE DATE NOT NULL
7
16550
by: (Pete Cresswell) | last post by:
I posted this in the MS Access group, but no luck. ------------------------------------------ I've got another stored procedure in the same app that returns multiple recordsets and the code works. But now I've written another SP and the code traps out with the 3251 message. The SP is writing two recordsets. When I run the SP in Query Analyzer, both recordsets appear.
1
1367
by: Yama | last post by:
Hello, Can someone tell me how to insert text into a table containing a TEXT field? How to update? I would like to create a stored procedure that take a text parameter and inserts it into a new column in my table. Then do the same stored procedure but this time to update the TEXT field. HELP!
34
10844
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have VBA code that wrote the results of that away to the db, either creating new records or updating existing records, whichever was relevant. This may also include deleting records. Now I generally do this by opening a recordset on the source data...
2
9476
by: Charles Wilt | last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access via a linked server from SQL Server 2000. The following select works fine: select * from prod400db.test.meldbf.InventoryHistory However, this insert statement fails: insert into prod400db.TEST.MELDBF.InventoryHistory
15
2912
by: Jaraba | last post by:
I am working in a project that I need to parse an arrayt an select records based upon the values parsed. I used the functions developed by Knut Stolze in his article 'Parsing Strings'. I am particulary having problems inserting records using a function. I am attaching the code for your review. Please, help. =================================--Function 1--====================================
9
6951
by: Oonz | last post by:
Hi Friends, How can we insert records in sorted order like consider a table No Name Phone 1 test1 12345 1 test1 23455 2 test2 68638
5
3829
by: slickdock | last post by:
I need to break my query into 3 groups: First 60 records (records 1-60) Next 60 records (records 61-121) Next 60 records (records 122-182) Of course I could use top values 60 for the first query, but where do I go from there?
2
3597
by: aeblank | last post by:
THE PROBLEM I'm running into performance issues generating and storing a randomly created graph in a SQL Server database. I have a T-SQL script that generates a graph, and then randomly connects the vertices in that graph to each other. I can see that my hard-drive is working very hard throughout the operation. The operation took about 2 hours (I just canceled it at this point, looked like it was about 10% done) with 200,000 vertices and an...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10222
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.