Wednesday, March 28, 2012

Query

Hi All

Thnks

I have a Datatable in which the rows have a unique id no appended to it

Example ColumnName : Manufacturer

Rows: Item1{6319c77a-b2c6-4b26-9528-99685de50d41}

Item2{e919c77a-b2c6-4b26-9528-99685de50d41}

Item3{ab19c77a-b2c6-4b26-9528-99685de50d41}

I need to insert into database only the unique id of the rows

6319c77a-b2c6-4b26-9528-99685de50d41 ie the num within {} brakets

How do I do this ?

Cheers

use this sample,

Code Snippet

Create Table #data (

[Value] Varchar(100)

);

Insert Into #data Values('Item1{6319c77a-b2c6-4b26-9528-99685de50d41}');

Insert Into #data Values('Item2{e919c77a-b2c6-4b26-9528-99685de50d41}');

Insert Into #data Values('Item3{ab19c77a-b2c6-4b26-9528-99685de50d41}');

Create Table #Targetdata (

[Value] UniqueIdentifier

);

insert into #Targetdata

Select Substring(Value,Charindex('{',Value)+1,CharIndex('}',Value)-1) From #Data

|||

Perhaps this will give you the direction you seek.


Code Snippet


SET NOCOUNT ON


DECLARE @.Manufacturer table
( [Rows] varchar(100) )


INSERT INTO @.Manufacturer VALUES ( 'Item1{6319c77a-b2c6-4b26-9528-99685de50d41}' )
INSERT INTO @.Manufacturer VALUES ( 'Item2{e919c77a-b2c6-4b26-9528-99685de50d41}' )
INSERT INTO @.Manufacturer VALUES ( 'Item3{ab19c77a-b2c6-4b26-9528-99685de50d41}' )


SELECT [ID] = substring( [Rows], 7, 36 )
FROM @.Manufacturer

ID
6319c77a-b2c6-4b26-9528-99685de50d41
e919c77a-b2c6-4b26-9528-99685de50d41
ab19c77a-b2c6-4b26-9528-99685de50d41


|||

Thanks a lot this works just fine .

|||

Thanks a lot this works just fine .

No comments:

Post a Comment