Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Code to Identify the delimiter

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-09-02 : 06:05:40
I am trying to write a code to identify the delimiter in the file ( which is in the form of table(id, raw) in system)
then I take this delimiter and pass it as a parameter to SP which perform cleaning of this file(table) and creates another clean table.

The problem I am facing is until now the file was coming with one fixed (TAB) delimiter, but now it has come with different (SPACE), now here I want to develop the code to identify the delimiter place it in a variable an pass this as parameter to cleaning SP.


begin

--here i want to develop code to identify delimiter from hosts_equiv file which has data as below
select * from hosts_equiv where left(raw,1) not in ('#','*') and isnull(raw,'')<>''

Raw id
---------------- ---
hiper USER1 1
hiper2 USER1 2
APX user2 3


Need to identify delimiter between e.g. hiper USER1 and pass it as a parameter to the raw_parse sp


declare @Tab varchar(10)
set @Tab = char(9)
exec raw_Parse
'hosts_equiv', -- From table ( entire file content is stored as table with Id record no sequence generated)
'CleanedHosts_Equiv', -- To table name, when passed it will clean the from table and places the cleaned data in to_table
@Tab, -- delimiter
'#', -- Comment character, line starts with # to be ignored
'HostName VARCHAR(MAX), UserName VARCHAR(MAX)' -- column names for the to_table passed dynamically ( we know before hand there are only 2 colummns
end

The raw parse SP is working fine if we pass the correct delimiter to it, else it errors out.




-Neil

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-02 : 12:06:29
why cant delimiter be fixed at source? dont you've control over it?

anyways if you want to do it at destination you've to compare it against lot of delimiter characters in a trial and error method

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -