SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


I need to compare and split the string and then save it in the detail_tb but dont know how ?


I need to compare and split the string and then save it in the detail_tb but dont know how ?

Author
Message
maida_rh
maida_rh
SSC-Enthusiastic
SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)

Group: General Forum Members
Points: 170 Visits: 111
thanks
maida_rh
maida_rh
SSC-Enthusiastic
SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)SSC-Enthusiastic (170 reputation)

Group: General Forum Members
Points: 170 Visits: 111
Thanks alot for responding and I check its perfect but do i need to add 'XX' to my string as My string is a message from another table ?

I will do somthing like this :

Select msg+'XX' from messageIn_TB where ..........

Is this a corrrect way to do that ? I asking coz all the splitting of string is done when a INSERT TRIGGER is fired on MessageIN_Tb and I didnt tried that right now .....


My thread link:

http://www.sqlservercentral.com/Forums/Topic1365750-392-1.aspx?Update=1
Jason-299789
Jason-299789
SSCarpal Tunnel
SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)

Group: General Forum Members
Points: 4803 Visits: 3232
I've seen that thread I'm not a fan of triggers on tables (personal preference) so hardly ever use them, but that doesnt mean its a bad thing.

It does need the +'XX' (or some other terminating character) as that was the only way I could get it to terminate the string and return the last data column.

_________________________________________________________________________
SSC Guide to Posting and Best Practices
dwain.c
dwain.c
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17165 Visits: 6431
Here's an interesting approach using a generic string splitter (DelimitedSplit8K) that can be found here: http://www.sqlservercentral.com/articles/Tally+Table/72993/


DECLARE @CHARACTERS TABLE (CHARS CHAR(1))
INSERT INTO @CHARACTERS VALUES
('N'), ('E'), ('M'), ('H'), ('T'), ('V'), ('L'), ('C' );

DECLARE @STRINGS TABLE (STRING VARCHAR(500));
INSERT INTO @STRINGS
SELECT '2449.555N06704.2855EM0701H071T44.098V11.764L0.372C1';

;WITH rCTE AS (
SELECT STRING, n, ItemNumber, Item
FROM @STRINGS
INNER JOIN (
SELECT n=ROW_NUMBER() OVER (ORDER BY (SELECT NULL)),CHARS
FROM @CHARACTERS) a ON n=1
CROSS APPLY dbo.DelimitedSplit8K(STRING, CHARS)
UNION ALL
SELECT STRING, b.n+1, c.ItemNumber, c.Item
FROM rCTE b
INNER JOIN (
SELECT n=ROW_NUMBER() OVER (ORDER BY (SELECT NULL)),CHARS
FROM @CHARACTERS) a ON a.n = b.n + 1
CROSS APPLY dbo.DelimitedSplit8K(Item, CHARS) c
WHERE b.ItemNumber <> 1
)
SELECT mvoltage=MAX(CASE WHEN n=1 THEN Item ELSE NULL END)
,mnorth=MAX(CASE WHEN n=2 THEN Item ELSE NULL END)
,meast=MAX(CASE WHEN n=3 THEN Item ELSE NULL END)
,mtime=MAX(CASE WHEN n=4 THEN Item ELSE NULL END)
,mtemperature=MAX(CASE WHEN n=5 THEN Item ELSE NULL END)
,mheight=MAX(CASE WHEN n=6 THEN Item ELSE NULL END)
,mcompraser=MAX(CASE WHEN n=7 THEN Item ELSE NULL END)
,mluman=MAX(CASE WHEN n=8 THEN Item ELSE NULL END)
FROM rCTE
WHERE ItemNumber = 1
GROUP BY STRING




Forgive me Jeff... Just having a bit of fun.


My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search