Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL Query mechanasism needs attention

Posted on 2016-09-05
5
41 Views
Last Modified: 2016-09-14
I have a SQL Query linked server job which I run on the hour, below is a simple process that updates some user info into a separate table that a 3rd party vendor uses for cross reference.

delete from [ZapCentral].dbo.SDContractParkers
insert into [ZapCentral].dbo.SDContractParkers
Select 'Active' as 'Status',
            ActiveContractParkingCards.CardNo ,
            ActiveContractParkingCards.UserNo,
            ActiveContractParkingCards.UserSurname,
            ActiveContractParkingCards.CustomerNo,
            ActiveContractParkingCards.CustomerSurname,
            ActiveContractParkingCards.PlateNo,
            ActiveContractParkingCards.ArticleNo

My challenge is that the PlateNo field is a memo data type Nvarchar (MAX) and could potentially hold (9) different string values separated by a comma - see insert below showing 3 :-
My approach would be to duplicate each row 3 times for this example with a single PlateNo entry for each.

snapshot
0
Comment
Question by:John-S Pretorius
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:DcpKing
ID: 41785193
And your question is?  How to do this?
As a suggestion, accumulate the data first on the "local" server. Then handle any rows with plate numbers containing commas, and then transmit the data to the remote server.

Handling the plate number fields with commas?
Well, you could use an extra field, initially set to zero when the holding table is filled. Set it to the number of commas in each row's Plate Number field:
len(PlateNumber) - len(replace(PlateNumber, ',', '')

Open in new window

gives the number of commas!

Then go to each marked row, add the right number of extra rows, and parse out the text between the commas. There's an example in this EE answer.

Hope this helps

Mike
0
 

Author Comment

by:John-S Pretorius
ID: 41785272
Thank you Mike, I am actually overthinking it - what I need to do is export only the PlateNo column into a single .txt file with one plate number per line i.e.

WYX
XBX3465
EF9571
7BXXX09
7EXXX67
5XXXX52
WVR3833
VBE1748
....................
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 41785517
Ha!!! LOL.
Remember: All the best answers involve doing less!

Mike
0
 

Accepted Solution

by:
John-S Pretorius earned 0 total points
ID: 41791723
I have been digging and found below from the link : http://blog.sqlauthority.com/2015/04/21/sql-server-split-comma-separated-list-without-using-a-function/

Work's beautifull..

Thanks to Mr. Pinal

SELECT UserSurname,
LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS Certs
FROM
(
SELECT UserSurname,CAST('<XMLRoot><RowData>' + REPLACE(PlateNo,',','</RowData><RowData>') +
'</RowData></XMLRoot>' AS XML) AS x
FROM   dbo.SDContractParkers
)t
CROSS APPLY x.nodes('/XMLRoot/RowData')m(n)
0
 

Author Closing Comment

by:John-S Pretorius
ID: 41797512
No one was able to resolve the challenge, I found a solution online.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question