I have a CSV file containing linked IDs eg 1,2,3
I have a table with two columns ID and LinkedID
I would like to pass the CSV string in and have the table updated so that each relationship is added as a new record
ID,LinkedID
1,2
1,3
2,1
2,3
3,1
3,2
Any ideas?
Thanks
Josh
6 1884
I have a CSV file containing linked IDs eg 1,2,3
I have a table with two columns ID and LinkedID
I would like to pass the CSV string in and have the table updated so that each relationship is added as a new record
ID,LinkedID
1,2
1,3
2,1
2,3
3,1
3,2
Any ideas?
Thanks
Josh
Why not import the CSV file into a table directly? (Enterprise Manager -> Tools -> Data Transformation Services -> Import Data ...)
because the list is dynamically generated.
Josh
You mean that you need a procedure that takes a CSV string (of the from "ID,LinkedID") as an input parameter and then adds the the record to the table? (If so I was confused of your mentioning a "CSV file".)
The following procedure does just that: -
create procedure csvinsert (@csvstring as varchar(200))
-
as
-
declare @commapos as int
-
-
set @commapos = charindex(',',@csvstring)
-
insert into IDTABLE VALUES(left(@csvstring,@commapos-1),right(@csvstring,len(@csvstring)-@commapos))
-
sorry shouldn't have used the phase 'csv file'. Let me try to explain again what i'm trying to do.
the sp would have a string input of '1,2,3'
from this i need to generate a list of all the possible combinations
1,2
1,3
2,1
2,3
3,1
3,2
which then need to be inserted into a two column table.
the string input could be any length eg '1,2,3,4,5' and so the generated list would be different.
i hope this makes sense.
thanks for your help
Josh
sorry shouldn't have used the phase 'csv file'. Let me try to explain again what i'm trying to do.
the sp would have a string input of '1,2,3'
from this i need to generate a list of all the possible combinations
1,2
1,3
2,1
2,3
3,1
3,2
which then need to be inserted into a two column table.
the string input could be any length eg '1,2,3,4,5' and so the generated list would be different.
i hope this makes sense.
thanks for your help
Josh
Next attempt :): -
create procedure create_linked_ids(@csvstring as varchar(200))
-
as
-
declare @pos as int, @lastpos as int
-
declare @temptbl TABLE (tmpid int)
-
-
set @lastpos = 1
-
set @pos = charindex(',',@csvstring)
-
while (@pos > 0)
-
begin
-
insert into @temptbl values (substring(@csvstring,@lastpos,@pos-@lastpos))
-
set @lastpos=@pos+1
-
set @pos=charindex(',',@csvstring,@lastpos)
-
end
-
insert into @temptbl values (substring(@csvstring,@lastpos,len(@csvstring)-@lastpos+1))
-
select a.tmpid 'ID',b.tmpid 'LinkedID' from @temptbl a, @temptbl b where a.tmpid<>b.tmpid
-
-
go
-
Use it like this: - exec create_linked_ids '1,2,3'
If the result has to go into a table then insert the 'INTO <tablename>' caluse into the last line of the procedure (before 'FROM').
Hope it helps
that works great! thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Carl Gilbert |
last post by:
Hi
I have some ASP code that I want to run from CD within a VB.NET windows
application with a web browser control.
However, to get the ASP pages to run without a server is proving quite...
|
by: ET |
last post by:
I don't know whats the problem, but after I added functions
to first verify, then relink linked tables if not found,
now I can't convert that database to MDE format.
I can split the database, but...
|
by: Jan |
last post by:
Hi:
I have an Access database that's been running (in one form or another)
for a couple of different clients for a few years. Now a new client has
requested that it be implemented with a SQL...
|
by: egoldthwait |
last post by:
I need to convert a 17mb access 2000 db to Oracle and house it in a
Citrix farm. The issue: we have never converted an Access Db to Oracle
but can probably use Oracle's Workbench to assist with...
|
by: Jorge |
last post by:
I want to convert this xml to pdf using cocoon
<?xml version="1.0" encoding="ISO-8859-1" ?>
<document>
<header>
<title>Pagina</title>
</header>
<body>
<h1>Link dei siti pił visitati da...
|
by: Bob Homes |
last post by:
In VB6, foreground and background colors of controls had to be assigned a
single number. If you knew the RGB values for the color, you still had to
convert them into the single number accepatable...
|
by: Aaron_nesbitt |
last post by:
Hi,
Is there any way to convert a sting (Pulled from a data tabel) into
VB.NET code?
The original case statment looked like this:
Select Case e.Link.ItemName
Case "frmNEWFORM"
Dim f As...
|
by: mark |
last post by:
The idea of this is very simle. The site is 800px wide and sits in the
middle of the browser window, on either side of the site I want a different
background image aligned against it. If I were...
|
by: donpro |
last post by:
Hi,
I've created a table where the header columns link to an AJAX function
which calls a PHP file and returns content - the purpose is to sort
the table on the heading.
The code snippet is:...
|
by: lenygold via DBMonster.com |
last post by:
I am tryieng to convert our time consuming recursive queries too very
efficient queries based
on nested set model.
The only problem is to convert an adjacency list model into a nested set
model,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |