Parsing Delimited String

Jul 3, 2013

parsing any delimited string (in above example it is using ',' as parsing delimiter. This query can be useful in many business scenarios where in we have input data as a long string containing delimited values.

declare
v_sql VARCHAR2(2000);
v_pos INTEGER;
v_differentiator VARCHAR2(10);

[code]...

View 4 Replies


ADVERTISEMENT

Parsing A Tab Delimited File

Dec 5, 2007

I have a tab delimited file with 122 columns. Can any one let me know if there is a better way of parsing/extracting few columns (say about 15) from the file and loading it into a table using SSIS.

View 1 Replies View Related

Parsing Variable Length Delimited Records

Mar 25, 2006

I am running SQLServer 2000 to parse and store records in the EDIX12
format. This consists of variable length delimited records which
I am passing to the "transforms" tab to process with VBScript.



The problem is though each segment has a defined number of fields, N,
the standard states that if the final M fieds are empty/blank they are
not to be sent. Thus, a segment defined to have 20 fields may
have 6 the first time I see it, 13 the next time, etc. To access
the columns in VBScript I use DTSSource("Col001"). This works as
long as the columns are there, but gives an error when they are
not. Is there a parameter telling me how many columns are
defined? Or is there something akin to IFEXISTS("Colxxx") or
exceptions?



How can I handle this situation? One suggestion has been to pass
the entire segment to the Transforms section and break it up there.



Finally, what resources can yuo point me to for reference? I'd
like to get good at using DTS since my client wants their project
written for it.



Thanks for yuor help,

--greg

View 1 Replies View Related

SQL Server 2008 :: Search Each And Every String In Comma Delimited String Input (AND Condition)

Mar 10, 2015

I have a scenario where in I need to use a comma delimited string as input. And search the tables with each and every string in the comma delimited string.

Example:
DECLARE @StrInput NVARCHAR(2000) = '.NET,Java, Python'

SELECT * FROM TABLE WHERE titleName = '.NET' AND titleName='java' AND titleName = 'Python'

As shown in the example above I need to take the comma delimited string as input and search each individual string like in the select statement.

View 3 Replies View Related

String Parsing

Jun 7, 2002

How to remove same repeated string in a column per row from a table? Looked at
replace, stuff string functions, but none take a column name as a parameter.

Help is appreciated.

Thanks,

View 1 Replies View Related

String Parsing

Apr 12, 2008

I found an article about string parsing but its done using db2

http://www.ibm.com/developerworks/db2/library/techarticle/0303stolze/0303stolze1.html

can anybody translate to Transact SQL specifically the example of create function elemIdx i didnt understand how he used recursion may b cuz the language is odd to me i didnt get it

Thanks much

View 1 Replies View Related

SQL String Parsing

Apr 18, 2008

I have a string that is coming from a legacy system

###T1937###U1875###U1960###U3287###U5926###U6388###U4408###T1909###U2620###U5025###U6354###U7072###U7074###U6715###U6714###U4085###U6441###U7067###U7073###U2392###U6348###U7758###U6717###U7755###U7069###U7756###U6350###U6760###U7070###D0002###D0001###U6238###U6349###U6353###U6355###F0005###U7750###U6351###U7757###

How can I convert above string to comma separted values

like one below so that it can be used for IN Clause for my SQL

'T1937','U1875','U1960','U3287','U5926','U6388','U4408','T1909','U2620','U5025','U6354','U7072','U7074','U6715','U6714','U4085','U6441','U7067','U7073','U2392','U6348','U7758','U6717','U7755','U7069','U7756','U6350','U6760','U7070','D0002','D0001','U6238','U6349','U6353','U6355','F0005','U7750','U6351','U7757'

Thanks in advance

View 17 Replies View Related

T-sql String Parsing

Jul 11, 2006

I have a series of strings (field name FullName) in a table (FullNames) that look like this:



FullNames

--------------

macdonald, ronald

Doe, John



I need to extract the first and last names. Here's my code:

select substring (fullname, 1, patindex( '%,%', fullname)-1) + ' ' +

substring (fullname, patindex( '%,%', fullname)+1, len(fullname) ) from FullNames



I hate having to use patindex twice in the same SELECT. Is there any way around this?



TIA,

Barkingdog

View 8 Replies View Related

SQL String Data Parsing

Sep 16, 2007

<p>
Hi everybody, I was hoping to get some advice something I can't quite get my head around.  I have a SQL db which contains a table with ratings using the AJAX rating control.
When someone rates an object, I need to select the current rating and then use those numbers to;
- calculate the new average
- add new score to total score
- increment number of votes by one.
 
I thought this can be best achieved using the SELECT statement and then parsing the SELECT string. (is the string comma separated?)
using each array, i'd need to convert this into integers and then do the calculation. and re-upload the data to the ratings table (using the UPDATE statement).
 
Is this the best way of proceeding?  I have tried initially to write the code using three sql statements. But that would mean to many requests from the server, right?
Below is the conde I have writting already.int myrating;
myrating = Rating1.CurrentRating;string getscore = "SELECT " +
"RatingScore" +"FROM Rating " +
"WHERE ItemID= '" + _ItemID+ "'";string getcount = "SELECT " +
"RatingCount" +"FROM Rating " +
"WHERE ItemID = '" + _ItemID + "'";string getaverage = "SELECT " +
"RatingAverage " +"FROM Rating " +"WHERE ItemID = '" + _ItemID + "'";
 
int _ratingscore;int _newscore; _ratingscore = int.Parse(getscore);
_newscore = _ratingscore + myrating; //add new rating score to old scoreint _ratingcount;
int _newcount;_ratingcount = int.Parse(getcount);
_newcount = _ratingcount + 1; //increase count by 1int _ratingaverage;
int _newaverage;_ratingaverage = int.Parse(getaverage);
_newaverage = _newscore / _newcount; //calculate new average rating
 otherwise
 otherwise would i be best off to do the following?...
string[] dbRatings = SQLstring.Split(',');
 ??
Any help would be appreciated.
Many thanks in advance.
Phil
 
</p>

View 2 Replies View Related

Parsing Character String

May 21, 2008

I'm running into a couple of performance issues with regards to the parsing of a text string. We have a function that will take a comma delimited character string, parse out the individual values, and then populate a temp table with those values. The two issues are 1.) the parsing process is VERY slow and 2.) there's a max to how large the string can be - at some point it could easily be 8000 characters or more in length.



Here are the function and the stored procedure wher eit occurs:




CREATE FUNCTION [dbo].[Split](@String varchar(MAX), @Delimiter char(1))

RETURNS @Results TABLE (Item nvarchar(4000))

AS



BEGIN

DECLARE @INDEX INT

DECLARE @SLICE nvarchar(4000)

-- HAVE TO SET TO 1 SO IT DOESNT EQUAL Z

-- ERO FIRST TIME IN LOOP

SELECT @INDEX = 1

WHILE @INDEX !=0



BEGIN

-- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER

SELECT @INDEX = CHARINDEX(@Delimiter,@STRING)

-- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE

IF @INDEX !=0

SELECT @SLICE = LEFT(@STRING,@INDEX - 1)

ELSE

SELECT @SLICE = @STRING

-- PUT THE ITEM INTO THE RESULTS SET

INSERT INTO @Results(Item) VALUES(@SLICE)

-- CHOP THE ITEM REMOVED OFF THE MAIN STRING

SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX)

-- BREAK OUT IF WE ARE DONE

IF LEN(@STRING) = 0 BREAK

END

RETURN

END

Procedure:


Code SnippetCREATE PROCEDURE [dbo].[RPTPatientAnalysis]

(

@stateList CHAR(2),

@employerIdList VARCHAR(4000),

@payerIdList VARCHAR(4000)

)

AS

SELECT

p.PAT_ID,

p.PAT_FirstName,

ISNULL(p.PAT_MiddleName,'') AS PAT_MiddleName,

p.PAT_LastName,

p.PAT_Gender,

CONVERT(VARCHAR(10),p.PAT_DOB,101) AS DOB,

p.PAT_AddressStreet1,

ISNULL(p.PAT_AddressStreet2,'') AS PAT_AddressStreet2,

p.PAT_AddressCity,

p.PAT_AddressStateProvince,

p.PAT_AddressPostalCode,

ISNULL(p.PAT_EmailAddress,'') AS PAT_EmailAddress,

p.PAT_PhoneNumber,

ISNULL(e.EMPLOYER_Name,'<Unknown>') AS EMPLOYER_Name,

ISNULL(p.PAT_OtherEmployerName,'') AS PAT_OtherEmployerName,

ISNULL(p.PAT_Comment,'') AS PAT_Comment,

ISNULL(p.PAT_PrimCareProv_PRIMCP_ID,'') AS PAT_PrimCareProv_PRIMCP_ID,

ISNULL(p.PAT_PrimCareProvAllowNotification,0) AS PAT_PrimCareProvAllowNotification,

ISNULL(p.PAT_PrimCareProvFullName,'') AS PAT_PrimCareProvFullName,

ISNULL(p.PAT_DoNotMail,0) AS PAT_DoNotMail,

ISNULL(p.PAT_UnderAgePermission,0) AS PAT_UnderAgePermission,

p.PAT_LastEandMCodingDateTime,

p.PAT_Desceased,

p.PAT_PCP_ID,

p.PAT_LastUpdatedDateTime,

ISNULL(p.PAT_PCPRecordType,0) AS PAT_PCPRecordType,

ISNULL(p.PAT_EnableEmailMarketing,0) AS PAT_EnableEmailMarketing,

ISNULL(p.PAT_EnablePortal,0) AS PAT_EnablePortal,

ISNULL(p.PAT_PortalID,0) AS PAT_PortalID,

ISNULL(e2.EMPLOYER_Name,'') AS EMPLOYER_Name,

ISNULL(p.PAT_OtherEmployerName,'') AS PAT_OtherEmployerName,

pcp.PRIMCP_ID,

ISNULL(pcp.PRIMCP_ADDR_ID,'') AS PRIMCP_ADDR_ID,

ISNULL(pcp.PRIMCP_ClinicName,'') AS PRIMCP_ClinicName,

ISNULL(pcp.PRIMCP_PhysicianFullname,'') AS PRIMCP_PhysicianFullname,

pcp.PRIMCP_DateDeactivated,

ISNULL(pcp.PRIMCP_Phone_MedicalRecordFax,'') AS PRIMCP_Phone_MedicalRecordFax,

ISNULL(pcp.PRIMCP_Phone_Voice,'') AS PRIMCP_Phone_Voice,

ISNULL(pcp.PRIMCP_MedicalRecords_Street1,'') AS PRIMCP_MedicalRecords_Street1,

ISNULL(pcp.PRIMCP_MedicalRecords_Street2,'') AS PRIMCP_MedicalRecords_Street2,

ISNULL(pcp.PRIMCP_MedicalRecords_City,'') AS PRIMCP_MedicalRecords_City,

ISNULL(pcp.PRIMCP_MedicalRecords_State,'') AS PRIMCP_MedicalRecords_State,

ISNULL(pcp.PRIMCP_MedicalRecords_Zip,'') AS PRIMCP_MedicalRecords_Zip,

ISNULL(pcp.PRIMCP_Street1,'') AS PRIMCP_Street1,

ISNULL(pcp.PRIMCP_Street2,'') AS PRIMCP_Street2,

ISNULL(pcp.PRIMCP_City,'') AS PRIMCP_City,

ISNULL(pcp.PRIMCP_State,'') AS PRIMCP_State,

ISNULL(pcp.PRIMCP_Zip,'') AS PRIMCP_Zip,

ISNULL(pcp.PRIMCP_DoNotFax,0) AS PRIMCP_DoNotFax,

pati.PATINS_InsuranceTypeID,

ISNULL(pati.PATINS_Account,'') AS PATINS_Account,

ISNULL(pati.PATINS_Group,'') AS PATINS_Group,

ISNULL(pati.PATINS_CopayType,'') AS PATINS_CopayType,

ISNULL(pati.PATINS_CopayAmount,0) AS PATINS_CopayAmount,

ISNULL(pati.PATINS_CollectFullAmount,0) AS PATINS_CollectFullAmount,

ISNULL(pati.PATINS_EmployerPays,0) AS PATINS_EmployerPays,

ISNULL(pati.PATINS_ZeroScreenCopay,0) AS PATINS_ZeroScreenCopay,

ISNULL(pati.PATINS_ZeroVaccineCopay,0) AS PATINS_ZeroVaccineCopay,

ISNULL(pati.PATINS_NonPar,0) AS PATINS_NonPar,

ISNULL(pati.PATINS_MedicarePlan,0) AS PATINS_MedicarePlan,

ISNULL(ipcl.INSPCAT_Description,'') AS INSPCAT_Description,

ISNULL(ip.INSP_Name,'') AS INSP_Name,

ISNULL(ip.INSP_ChargeFullPrice,0) AS INSP_ChargeFullPrice,

ISNULL(ip.INSP_CopayApplies,0) AS INSP_CopayApplies,

CONVERT(VARCHAR(10),ip.INSP_DeactivatedDate,101) AS INSP_DeactivatedDate,

ISNULL(ip.INSP_EligibilityActive,0) AS INSP_EligibilityActive,

CONVERT(VARCHAR(10),ip.INSP_PromoStartDate,101) AS INSP_PromoStartDate,

CONVERT(VARCHAR(10),ip.INSP_PromoEndDate,101) AS INSP_PromoEndDate


FROM dbo.patient AS p

LEFT JOIN dbo.Employer AS e ON p.PAT_EMPLOYER_ID = e.EMPLOYER_ID

LEFT JOIN dbo.Employer AS e2 ON p.PAT_SecondaryEMPLOYER_ID = e2.EMPLOYER_ID

LEFT JOIN dbo.PrimaryCareProvider AS pcp ON p.PAT_PCP_ID = pcp.PRIMCP_ID

LEFT JOIN dbo.PatientInsurance AS pati ON p.PAT_ID = pati.PATINS_PAT_PERS_ID AND PATINS_InsuranceTypeID = 1

LEFT JOIN dbo.InsurancePayer AS ip ON pati.PATINS_INSP_ID = ip.INSP_ID

LEFT JOIN dbo.InsurancePayerCategoryLookup AS ipcl ON ip.INSP_INSPCAT_ID = ipcl.INSPCAT_ID

WHERE p.PAT_AddressStateProvince IN (SELECT Item FROM dbo.SplitVarcharMax(@stateList,','))

AND PAT_EMPLOYER_ID IN (SELECT Item FROM dbo.SplitVarcharMax(@employerIdList,','))

AND pati.PATINS_INSP_ID IN (SELECT Item FROM dbo.SplitVarcharMax(@payerIdList,','))


Is there a faster / more efficient way to accomplish the above?

Any insight would be appreciated!!

View 9 Replies View Related

T-SQL (SS2K8) :: Parsing A String

May 18, 2015

I have a table Alert_Types with these fields :

alert_id,
alert_source,
body,

Now whenever a new alert is registered record goes in table like

alert_id = 1,
alert_source= document_detail_view,
body = Document ID: @document_id
Customer Name: @customer_name
Item name: @item_name
Quantity: @qty

it was simple to parse simple variables using replace functions. eg. REPLACE(@str, '@customer_name', @customer_name). It worked like mail merge.the converted string was then sent forward using a webservice.now my requirement is to add conditional values in body field e.g:

body = Document ID: @document_id
Customer Name: @customer_name
Item name: @item_name
Quantity: @qty
IF isnull(@rate, 0) > 0 Rate: @rate
IF isnull(@rate, 0) > 0 Amount: @amount

how can i parse strings like this. I'm open to change format of values for body field.

View 9 Replies View Related

Parsing Character String

May 21, 2008



I'm running into a couple of performance issues with regards to the parsing of a text string. We have a function that will take a comma delimited character string, parse out the individual values, and then populate a temp table with those values. The two issues are 1.) the parsing process is VERY slow and 2.) there's a max to how large the string can be - at some point it could easily be 8000 characters or more in length.



Here are the function and the stored procedure where it occurs:


CREATE FUNCTION [dbo].[Split](@String varchar(MAX), @Delimiter char(1))
RETURNS @Results TABLE (Item nvarchar(4000))
AS
BEGIN
DECLARE @INDEX INT
DECLARE @SLICE nvarchar(4000)
-- HAVE TO SET TO 1 SO IT DOESNT EQUAL ZERO
-- FIRST TIME IN LOOP
SELECT @INDEX = 1
WHILE @INDEX !=0
BEGIN
-- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER
SELECT @INDEX = CHARINDEX(@Delimiter,@STRING)
-- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE
IF @INDEX !=0
SELECT @SLICE = LEFT(@STRING,@INDEX - 1)
ELSE
SELECT @SLICE = @STRING
-- PUT THE ITEM INTO THE RESULTS SET
INSERT INTO @Results(Item) VALUES(@SLICE)
-- CHOP THE ITEM REMOVED OFF THE MAIN STRING
SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX)
-- BREAK OUT IF WE ARE DONE
IF LEN(@STRING) = 0 BREAK
END
RETURN
END

--------------------

...and the stored procedure:


CREATE PROCEDURE [dbo].[RPTPatientAnalysis]
(
@stateList CHAR(2),
@employerIdList VARCHAR(4000),
@payerIdList VARCHAR(4000)
)
AS
SELECT
p.PAT_ID,
p.PAT_FirstName,
ISNULL(p.PAT_MiddleName,'') AS PAT_MiddleName,
p.PAT_LastName,
p.PAT_Gender,
CONVERT(VARCHAR(10),p.PAT_DOB,101) AS DOB,
p.PAT_AddressStreet1,
ISNULL(p.PAT_AddressStreet2,'') AS PAT_AddressStreet2,
p.PAT_AddressCity,
p.PAT_AddressStateProvince,
p.PAT_AddressPostalCode,
ISNULL(p.PAT_EmailAddress,'') AS PAT_EmailAddress,
p.PAT_PhoneNumber,
ISNULL(e.EMPLOYER_Name,'<Unknown>') AS EMPLOYER_Name,
ISNULL(p.PAT_OtherEmployerName,'') AS PAT_OtherEmployerName,
ISNULL(p.PAT_Comment,'') AS PAT_Comment,
ISNULL(p.PAT_PrimCareProv_PRIMCP_ID,'') AS PAT_PrimCareProv_PRIMCP_ID,
ISNULL(p.PAT_PrimCareProvAllowNotification,0) AS PAT_PrimCareProvAllowNotification,
ISNULL(p.PAT_PrimCareProvFullName,'') AS PAT_PrimCareProvFullName,
ISNULL(p.PAT_DoNotMail,0) AS PAT_DoNotMail,
ISNULL(p.PAT_UnderAgePermission,0) AS PAT_UnderAgePermission,
p.PAT_LastEandMCodingDateTime,
p.PAT_Desceased,
p.PAT_PCP_ID,
p.PAT_LastUpdatedDateTime,
ISNULL(p.PAT_PCPRecordType,0) AS PAT_PCPRecordType,
ISNULL(p.PAT_EnableEmailMarketing,0) AS PAT_EnableEmailMarketing,
ISNULL(p.PAT_EnablePortal,0) AS PAT_EnablePortal,
ISNULL(p.PAT_PortalID,0) AS PAT_PortalID,
ISNULL(e2.EMPLOYER_Name,'') AS EMPLOYER_Name,
ISNULL(p.PAT_OtherEmployerName,'') AS PAT_OtherEmployerName,
pcp.PRIMCP_ID,
ISNULL(pcp.PRIMCP_ADDR_ID,'') AS PRIMCP_ADDR_ID,
ISNULL(pcp.PRIMCP_ClinicName,'') AS PRIMCP_ClinicName,
ISNULL(pcp.PRIMCP_PhysicianFullname,'') AS PRIMCP_PhysicianFullname,
pcp.PRIMCP_DateDeactivated,
ISNULL(pcp.PRIMCP_Phone_MedicalRecordFax,'') AS PRIMCP_Phone_MedicalRecordFax,
ISNULL(pcp.PRIMCP_Phone_Voice,'') AS PRIMCP_Phone_Voice,
ISNULL(pcp.PRIMCP_MedicalRecords_Street1,'') AS PRIMCP_MedicalRecords_Street1,
ISNULL(pcp.PRIMCP_MedicalRecords_Street2,'') AS PRIMCP_MedicalRecords_Street2,
ISNULL(pcp.PRIMCP_MedicalRecords_City,'') AS PRIMCP_MedicalRecords_City,
ISNULL(pcp.PRIMCP_MedicalRecords_State,'') AS PRIMCP_MedicalRecords_State,
ISNULL(pcp.PRIMCP_MedicalRecords_Zip,'') AS PRIMCP_MedicalRecords_Zip,
ISNULL(pcp.PRIMCP_Street1,'') AS PRIMCP_Street1,
ISNULL(pcp.PRIMCP_Street2,'') AS PRIMCP_Street2,
ISNULL(pcp.PRIMCP_City,'') AS PRIMCP_City,
ISNULL(pcp.PRIMCP_State,'') AS PRIMCP_State,
ISNULL(pcp.PRIMCP_Zip,'') AS PRIMCP_Zip,
ISNULL(pcp.PRIMCP_DoNotFax,0) AS PRIMCP_DoNotFax,
pati.PATINS_InsuranceTypeID,
ISNULL(pati.PATINS_Account,'') AS PATINS_Account,
ISNULL(pati.PATINS_Group,'') AS PATINS_Group,
ISNULL(pati.PATINS_CopayType,'') AS PATINS_CopayType,
ISNULL(pati.PATINS_CopayAmount,0) AS PATINS_CopayAmount,
ISNULL(pati.PATINS_CollectFullAmount,0) AS PATINS_CollectFullAmount,
ISNULL(pati.PATINS_EmployerPays,0) AS PATINS_EmployerPays,
ISNULL(pati.PATINS_ZeroScreenCopay,0) AS PATINS_ZeroScreenCopay,
ISNULL(pati.PATINS_ZeroVaccineCopay,0) AS PATINS_ZeroVaccineCopay,
ISNULL(pati.PATINS_NonPar,0) AS PATINS_NonPar,
ISNULL(pati.PATINS_MedicarePlan,0) AS PATINS_MedicarePlan,
ISNULL(ipcl.INSPCAT_Description,'') AS INSPCAT_Description,
ISNULL(ip.INSP_Name,'') AS INSP_Name,
ISNULL(ip.INSP_ChargeFullPrice,0) AS INSP_ChargeFullPrice,
ISNULL(ip.INSP_CopayApplies,0) AS INSP_CopayApplies,
CONVERT(VARCHAR(10),ip.INSP_DeactivatedDate,101) AS INSP_DeactivatedDate,
ISNULL(ip.INSP_EligibilityActive,0) AS INSP_EligibilityActive,
CONVERT(VARCHAR(10),ip.INSP_PromoStartDate,101) AS INSP_PromoStartDate,
CONVERT(VARCHAR(10),ip.INSP_PromoEndDate,101) AS INSP_PromoEndDate
FROM dbo.patient AS p
LEFT JOIN dbo.Employer AS e ON p.PAT_EMPLOYER_ID = e.EMPLOYER_ID
LEFT JOIN dbo.Employer AS e2 ON p.PAT_SecondaryEMPLOYER_ID = e2.EMPLOYER_ID
LEFT JOIN dbo.PrimaryCareProvider AS pcp ON p.PAT_PCP_ID = pcp.PRIMCP_ID
LEFT JOIN dbo.PatientInsurance AS pati ON p.PAT_ID = pati.PATINS_PAT_PERS_ID AND PATINS_InsuranceTypeID = 1
LEFT JOIN dbo.InsurancePayer AS ip ON pati.PATINS_INSP_ID = ip.INSP_ID
LEFT JOIN dbo.InsurancePayerCategoryLookup AS ipcl ON ip.INSP_INSPCAT_ID = ipcl.INSPCAT_ID
WHERE p.PAT_AddressStateProvince IN (SELECT Item FROM dbo.SplitVarcharMax(@stateList,','))
AND PAT_EMPLOYER_ID IN (SELECT Item FROM dbo.SplitVarcharMax(@employerIdList,','))
AND pati.PATINS_INSP_ID IN (SELECT Item FROM dbo.SplitVarcharMax(@payerIdList,','))



Is there a faster / more efficient way to accomplish the above?


Any insight would be appreciated!!

View 15 Replies View Related

String Parsing And Expression Builder....

Oct 10, 2007

I can't figure this one out. I don't have enough knowledge of the string functions I guess.

I need to pull a value out of a variable I setup in a for each loop. The value is the filename/path of each source file being processed. Let's say the variable that has the source file path is called VAR1.

One sort of off topic thing I've noticed is when watch the variable in bebug mode and I look at the value of VAR1 it has double back slashes. Here's an example of the value of VAR1:

"\\L3KRZR6.na.xerox.net\C$\Documents and Settings\ca051731\Desktop\Project4\DPT_20070926.ver"

How come the back slashes have been doubled? And do I need to account for that when I start parsing the string value?

Anyway, I need to grab part of the filename from VAR1 and I need the value populated at the start of the for each loop container - ideally when I capture VAR1 in the for each container. I'll be using the string in drop table, create table and create index statements before the actual Data Flow task within the overall package

In the above example I need to grab the characters before the underscore and after the last \. So I'd need the string "DPT" captured in this example.

The actual string could be 1 to 3 characters long, even though this example has it as 3 long.

Underscores could exist anywhere in the actual UNC path once this package is moved to our actual system environments so I can't key off of the underscore.

Because I can't count on the string being a fixed lenght I can't just use a positional string function and grab specific text starting/ending at specific points.

Is there a way to use the various string functions in the expression builder to grab the text between the right most underscore and the right most back slashes or something like that? Ideally I'd like to setup a new expression based packed scope variable called VAR2 and build it using string functions applied to VAR1.

View 1 Replies View Related

Reading File As One String, Then Parsing - How To Do This?

May 7, 2007

Hi,



The suggestion to do this is buried deep in one of my posts, however I still do not have a clear idea of how to do this.



I have a flat file which has several "bad rows" in it. Because file error redirection is buggy, I need a manual approach to get rid of these incomplete rows in my data file.



Phil, you suggested I read the file as one long string, then parse out the bad rows (using a script?).... however I have no idea as to how to actually do this.



I was wondering if it's possible to clarify the steps involved in doing this, or perhaps point me to an example I can look at, as I cannot seem to get around this problem on my own.



Thanks much!!

View 24 Replies View Related

Quotes Around The Comma Delimited String

Oct 18, 2005

I am trying to build a dynamic where  statement for my sql stored prcoedure
  if len(@Office) > 0   select @strWhereClause = N'cvEh.chOfficeId in (select id from dbo.csfParseDeLimitedText( ' + @vchOffice  +  ',' + ''',''' + '))' + ' and ' + @strWhereClause
In this case users can enter comma delimited string in their search criteria. So if they enter we1, we2, we3 then my sql statement should look like
select @strWhereClause = cvEh.chOfficeId in (select id from dbo.csfParseDeLimitedText('we1', 'we2', 'we3'),',')
My csfParseDeLimitedText function looks like this
Create  FUNCTION [dbo].[csfParseDeLimitedText] (@p_text varchar(4000), @p_Delimeter char(1))RETURNS @results TABLE (id varchar(100))ASBEGIN declare @i1 varchar(200)declare @i2 varchar(200)declare @tempResults Table (id varchar(100))while len(@p_text) > 0 and charindex(@p_Delimeter, @p_text) <> 0beginselect @i1 = left(@p_text, charindex(@p_Delimeter, @p_text) - 1)insert @tempResults select @i1select @p_text = right(@p_text, len(@p_text) - charindex(@p_Delimeter,@p_text))endinsert @tempResults select @p_text
insert @resultsselect *from @tempResultsreturnEND
 
My problem is it does not put quotes around the comma delimited stringso I want to put 'we1' , 'we2'. These single quotes are not coming in the dynamic sql statement. How can I modify my query so that single quotes around each entry should show up.
Any help will be greatky appreciated.
Thanks

View 1 Replies View Related

SELECT WHERE IN Comma Delimited String

Jun 3, 2008

Hello

I have a table with column Options where each field contains a comma delimited list of ID numbers.

I want to select any records where a certain ID number appears in that list.

So something like:

SELECT * FROM Table t1
WHERE MyID IN (SELECT Options FROM Table t2 WHERE t1.ID = t2.ID)

But that gives me the error:

Syntax error converting the varchar value '39,20' to a column of data type int.

I feel I'm close though! Could anyone point me in the right direction?

Many thanks

Square

View 3 Replies View Related

Insert A Comma Delimited String

Nov 22, 2013

I have a problem in a stored procedure trying to insert a comma delimited list into rows.The parameters for example would be somthing like....

@GarageID int = 20,
@Cars nVarChar(200) = Ford~Fiesta,BMW~320,Volvo~340,Jaguar~XJS

I need to split where the comma is for each new row, and separate each value from either side of the '~' like so....

GarageID Make Model
--------------------------------
20 Ford Fiesta
20 BMW 320
20 Volvo 340
20 Jaguar XJS

View 2 Replies View Related

Splitting A Comma Delimited String

Oct 1, 2007

I have a string like say: '3:4:5:4,2:4:1,4:1:2:5:2'. Now I need to split the substrings delimited by commas. So my final output shall be

3:4:5:4
2:4:1
4:1:2:5:2


I did write a piece of code to achieve the same, but I feel its not so efficient. Can anyone suggest me a better way, if any? My code is as follows:

Declare @person as varchar(255), @cnt smallint,@loc smallint,@prevloc smallint, @str varchar(255)
Select @prevloc=0,@loc=1,@cnt=1,@person = '3:4:5:4,2:4:1,4:1:2:5:2'
While @loc != 0
begin
set @prevloc=(case when @loc = 1 then 0 else @loc end) +1
set @loc = charindex(',',@person,@loc+1)
Set @str = substring(@person,@prevloc,(Case when @loc = 0 then len(@person) - @prevloc + 1 else @loc - @prevloc end))
print 'String = ' + @Str
set @cnt=@cnt+1
end

RESULT
------
String = 3:4:5:4
String = 2:4:1
String = 4:1:2:5:2


Note: My actual purpose is to also sub split it again with ':' delimiter too. So looking for an efficient code.

View 4 Replies View Related

Lots Of Individual Insert Commands Or String Parsing In Sql?

Feb 16, 2007

Wondering what's the preferred method for this.  I've got a scenario that a user is updating some content on a page and I need to update my word catalogs for my search feature.  I have some code currently to filter out words that are too small, make sure there are no duplicates and to count how many occurrences there are of each.  What I'm wondering is, does it make more sense to do a loop in my code to run all the insert commands to place the new words in the database, should I try sticking them together in one string and parse them when they get up there or is there a better method someone can suggest?

View 1 Replies View Related

SQL 2012 :: Parsing Out Data String With Text Delimiters

Nov 5, 2014

I'm trying to parse out a line of data that is separated by the text "atc1.", "atc2." etc.

For example,

[atc1.123/atc2.456/atc3.789/atc4.xyz/]

If I only want the data after atc2., then I could search the string for "atc2." and collect all the characters afterwards. But how can I make sure to trim off all the data after "atc3." to make sure I'm only collecting "456" from the example above?

View 2 Replies View Related

String Parsing - Grab Some Key Value Pairs From Text In Column

Jul 21, 2014

I want to grab some key value pairs from the text in sql column

e.g.

some text[Key1=Val1]some text[Key2=Val2][Key3=Val3]some text

I want a function which takes Keyname as input & returns the value related with it if found.

GetValueFmKey('Key1') should return Val1 and like on.

View 1 Replies View Related

Stored Procedure And Comma Delimited String

Dec 8, 2006

I'm passing a comma delimited string to my SP, e.g.:"3,8,10,16,23,24"I need to retreive each number in this string and for every number found I need to execute some sode, say add "AND SportID="+numberfoundHow can I do that?

View 6 Replies View Related

Multiple Rows Into A Comma Delimited String

May 22, 2007

I have the following table:id name1 yes2 no3 what4 is5 this6 niceThe amount of rows can vary from 1 to 50. I only need the name column.What SQL statement do I have to execute to get the following:yes,no,what,is,this,nice,  (trailing , is acceptable)Thanks!

View 1 Replies View Related

Splitting Space Delimited String Inline

May 20, 2008

So we have a field called forenames, and it needs to be split into fields forename_1, forename_2, forename_3, forename_4 (don't ask).

Ok, I've come up with this so far, which works, but is pretty nacky in my opinion. Has any one got a better way of achieving this?

SELECT forenames
, Replace(forenames, ' ', '.')
, Reverse(ParseName(Replace(Reverse(forenames), ' ', '.'), 1)) As [f1]
, Reverse(ParseName(Replace(Reverse(forenames), ' ', '.'), 2)) As [f2]
, Reverse(ParseName(Replace(Reverse(forenames), ' ', '.'), 3)) As [f3]
, Reverse(ParseName(Replace(Reverse(forenames), ' ', '.'), 4)) As [f4]
FROM ( SELECT 'John' As [forenames]
UNION SELECT 'John Paul'
UNION SELECT 'John Paul George'
UNION SELECT 'John Paul George Ringo'
) As [x]

Results

forenames (no column name) f1 f2 f3 f4
---------------------- ---------------------- ---- ---- ------ -----
John John John NULLNULL NULL
John Paul John.Paul John PaulNULL NULL
John Paul George John.Paul.George John PaulGeorgeNULL
John Paul George Ringo John.Paul.George.Ringo John PaulGeorgeRingo

View 7 Replies View Related

SQL Server 2014 :: Creating A Delimited String?

Apr 7, 2015

I have a need to create a delimited string so that I can use this to create a data driven subscription on SSRS.

In the below code, I need to create a delimited string using the branch number, grouped by the email address

USE tempdb
GO
IF OBJECT_ID('tempdb..#emails') IS NOT NULL
BEGIN
DROP TABLE #emails

[code]....

View 7 Replies View Related

How To Parse A String Column With Comma Delimited

Jul 20, 2005

Hi,I would like to parse out each value that is seperatedby a comma in a field and use that value to join to another table.What would be the easiest way to do so without having towrite a function or routine ?EX.Table AAACOL1 COL21 11, 124, 1562 11, 505, 600, 700, ...Table BBBCOL1 COL211 Desc11124 Desc124156 Desc 156

View 2 Replies View Related

Transact SQL :: How To Split Comma Delimited String

Oct 8, 2008

I have a parameter called Id in my SP which will be of nvarchar data type and i'm going to get the multiple ids at a time seperated by commas in that parameter from the application. Now my requirement is to update a table with these comma seperated ids in seperate rows.

For example, if i have 2 parameters called Id1 and Id2. Id1 will contain only one value and will be of int data type and Id2 will be of nvarchar data type as i can get multiple ids delimited by a comma from the application.

Suppose Id1 = 1 and Id2 = '1,2,3,4'. Then I have to update id2 in the tables seperately like wherever Id1 is '1' i need to update Id2 column for 4 rows with the value 1, 2, 3, 4 respectively in different rows.
 
how can i do this in T-SQL? How can i split the data of parameter Id2 in 4 different rows?

View 24 Replies View Related

Sending A Delimited String To A As Input Stored Procedure

Jun 28, 2004

if i send the string

2,3,4,5 to a stored procedure...

is there a way i could split those values for input into the database? no, right? i would need a seperate stored procedure that would take each value one at a time...correct?

View 7 Replies View Related

How Do I Split And Insert A Comma Delimited String To A Table?

Oct 13, 2004

I am passing in a string of dates, delimited by a comma.

So

01/01/04, 02/01/04, 03/01/04

etc

I would like to enter each of these values into a table via an INSERT stored procedure.

Does anyone have any code for this?

View 1 Replies View Related

T-SQL (SS2K8) :: Split Pipe Delimited String Into Two Columns

Mar 6, 2014

I have a single string "XYZ00001|Test_b|XYZ00002|Test_a|XYZ00003|Test_c" that will continue to grow over time.

Is there a way I can extract the values from the string into two separate columns?

XYZ0001 Test_b
XYZ0002 Test_a
XYZ0003 Test_c

View 5 Replies View Related

SQL Server 2012 :: Hyphen Delimited String Manipulation

Oct 19, 2015

I am having a field 'Flight Route that holds hyphen delimited character sequences.

E.g. : ABC-BCD-DEF-EFG.

My requirement is like this:

If the flight route is:

ABC-BCD-BCD-DEF make it ABC-BCD-DEF
ABC-ABC-BCD-DEF make it ABC-BCD-DEF

i.e. 'whenever a sequence repeats,only one appearance of that sequence should be displayed.The field Flight Route has to be updated with this replaced string.

View 6 Replies View Related

Stored Procedure To Parse Delimited String To Table?

Apr 10, 2015

SP to parse a delimited string and insert the result in a table. I am using SQL Server 2008 R2. I have 2 tables - RawData & WIP. I have Robots on a manufacturing line capable of moving data to a DB. I move the raw data to RawData. On insert [RawData], I want to parse the string and move the contents to WIP as indicated below. I will run reports against the WIP Table.

Also, after the string is parsed, I'd like to change the Archive column, the _0 at the end of the raw string to 1 in the WIP table to indicate a successful parse.

Sample Strings - [RawData Table]
04102015_114830_10_013_9_8_6_99999_Test 1_1_0
04102015_115030_10_013_9_8_6_99999_Test 2_1_0

Desired Output - [WIP Table]

Date Time Plant Program Line Zone Station BadgeID Message Alarm Archive
-----------------------------------------------------------------------------------
04102015 114830 10 13 9 8 6 99999 Test 1 1 1
04102015 115030 10 13 9 8 6 99999 Test 2 1 1

View 16 Replies View Related

SQL Server 2008 :: Text String Parsing To Apply Operators To Datasets?

Aug 7, 2015

I have a problem at the moment, where the client wants to be able to type in a custom algebraic formula with add/minus operators, and then to have this interpreted, so that the related datasets are then added and returned as a single dataset.

An example would be having a formula stored of [a] + [b] - [c]

and if I were to write the SQL to apply that formula, I might write something like (let's assume 1:1 relationships with the ID's)

select a.a + b.b - c.c as [result]
from z
inner join tblA a on z.id = a.id
inner join tblB b on z.id = b.id
inner join tblC c on z.id = c.id

The formula can change though, maybe things like:

[a] + [b] + [c] + [d]
[a] + [b]

The developer before me wrote something SQL-based where they parsed the string and assigned each value of the formula as either positive or negative (e.g A is positive, B is positive, C is negative, now sum the datasets to get the result), and then created one large table of values then summed them. This does (kind of) work, I'm just contemplating potential alternatives, as it is quite a slow process, and feels like it is quite convoluted, when I get into the details. If I were to do something like this in SQL, I'd normally want each part of the expression to be a column, and then to just apply the operators, but because the formula can change, then the SQL would need to be somehow dynamic for this approach.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved