dbTalk Databases Forums  

SQL problem

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss SQL problem in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Vardinghus
 
Posts: n/a

Default SQL problem - 03-13-2005 , 06:42 AM






Hi All

Have a table with this structure

Code Name

100000010 Project A - area 1
100000011 Projekt A - area x
200000010 Project B - area 1
200000011 Projekct - area x
...

From this I would like to create a new table with this structure

1000000 Project A - area 1
2000000 Project B - area 1

I need to get left(code,7) but my problem is how to select one of the name s
and attaching this to the 7 digit code. In my example below I just chose the
first Name I encounter - I cannot
take x characteres because this differ.

But is it possible to select the name from the first...if so - how ?

/Michael V.



Reply With Quote
  #2  
Old   
Tom Moreau
 
Posts: n/a

Default Re: SQL problem - 03-13-2005 , 08:08 AM






Try:

select
left (Code, 7) as Code
, Name
from
MyTable o
where
o.Code =
(
select
min (i.Code)
from
MyTable i
where
left (i.Code, 7) = left (o.Code, 7)
)

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
..
"Michael Vardinghus" <michaelvardinghus (AT) hotmail (DOT) com> wrote

Hi All

Have a table with this structure

Code Name

100000010 Project A - area 1
100000011 Projekt A - area x
200000010 Project B - area 1
200000011 Projekct - area x
...

From this I would like to create a new table with this structure

1000000 Project A - area 1
2000000 Project B - area 1

I need to get left(code,7) but my problem is how to select one of the name s
and attaching this to the 7 digit code. In my example below I just chose the
first Name I encounter - I cannot
take x characteres because this differ.

But is it possible to select the name from the first...if so - how ?

/Michael V.



Reply With Quote
  #3  
Old   
Michael Vardinghus
 
Posts: n/a

Default Re: SQL problem - 03-14-2005 , 03:15 PM



Sounds like the way to go ...

Thanks Tom

"Tom Moreau" <tom (AT) dont (DOT) spam.me.cips.ca> wrote

Quote:
Try:

select
left (Code, 7) as Code
, Name
from
MyTable o
where
o.Code =
(
select
min (i.Code)
from
MyTable i
where
left (i.Code, 7) = left (o.Code, 7)
)

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
.
"Michael Vardinghus" <michaelvardinghus (AT) hotmail (DOT) com> wrote in message
news:uDNhWo8JFHA.4028 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi All

Have a table with this structure

Code Name

100000010 Project A - area 1
100000011 Projekt A - area x
200000010 Project B - area 1
200000011 Projekct - area x
..

From this I would like to create a new table with this structure

1000000 Project A - area 1
2000000 Project B - area 1

I need to get left(code,7) but my problem is how to select one of the name
s
and attaching this to the 7 digit code. In my example below I just chose
the
first Name I encounter - I cannot
take x characteres because this differ.

But is it possible to select the name from the first...if so - how ?

/Michael V.





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.