Unix Technical Forum

Creating temporary table

This is a discussion on Creating temporary table within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, How can I create a temporary table say "Tblabc" with column fields ShmCoy char(2) ShmAcno char(10) ShmName1 varchar(60) ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:14 PM
Omavlana
 
Posts: n/a
Default Creating temporary table

Hi,

How can I create a temporary table say "Tblabc" with column fields

ShmCoy char(2)
ShmAcno char(10)
ShmName1 varchar(60)
ShmName2 varchar(60)

and fill the table from the data extracted from the statement...

"select logdetail from shractivitylog"


The above query returns single value field the data seperated with a '·'

Ex:
BR··Light Blue Duck··

in this case I should get
ShmCoy = 'BR'
ShmAcno = ''
ShmName1 = 'Light Blue Duck'
ShmName2 = ''

I want to do this job with single SQL query. Is it possible. Pls help.


Herewith I am providing the sample data

BR··Light Blue Duck··
·0234578···
BR··Aqua Duck··
·0234586···
UB··Aqua Duck··


Regards,
Omav
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:15 PM
Mauro
 
Posts: n/a
Default Re: Creating temporary table

Hi.

I think that is better using a stored procedure, but you can try with
this:



create table shractivitylog (logdetail varchar(50))
go

insert into shractivitylog values ('BR··Light Blue Duck··');
insert into shractivitylog values ('·0234578···');
insert into shractivitylog values ('BR··Aqua Duck··');
insert into shractivitylog values ('·0234586···');
insert into shractivitylog values ('UB··Aqua Duck··');

select cast(substring(logdetail,
1,
charindex('·',logdetail)-1
) as char(2)) as ShmCoy,
cast(substring(logdetail,
charindex('·',logdetail)+1,
charindex('·',logdetail,charindex('·',logdetail)+1 )-(charindex('·',logdetail)+1)
) as char(10)) as ShmAcno,
cast(substring(logdetail,
charindex('·',logdetail,charindex('·',logdetail)+1 )+1,
charindex('·',logdetail,charindex('·',logdetail,ch arindex('·',logdetail)+1)+1)-(charindex('·',logdetail,charindex('·',logdetail)+ 1)+1)
) as varchar(60)) as ShmName1,
cast(substring(logdetail,
charindex('·',logdetail,charindex('·',logdetail,ch arindex('·',logdetail)+1)+1)+1,
charindex('·',logdetail,charindex('·',logdetail,ch arindex('·',logdetail,charindex('·',logdetail)+1)+ 1)+1)-(charindex('·',logdetail,charindex('·',logdetail,c harindex('·',logdetail)+1)+1)+1)
) as varchar(60)) as ShmName2
into ##tblabc
from shractivitylog

select * from ##tblabc


Bye!


kiran@boardroomlimited.com (Omavlana) wrote in message news:<b14098ab.0310080226.64bf03c6@posting.google. com>...
> Hi,
>
> How can I create a temporary table say "Tblabc" with column fields
>
> ShmCoy char(2)
> ShmAcno char(10)
> ShmName1 varchar(60)
> ShmName2 varchar(60)
>
> and fill the table from the data extracted from the statement...
>
> "select logdetail from shractivitylog"
>
>
> The above query returns single value field the data seperated with a '·'
>
> Ex:
> BR··Light Blue Duck··
>
> in this case I should get
> ShmCoy = 'BR'
> ShmAcno = ''
> ShmName1 = 'Light Blue Duck'
> ShmName2 = ''
>
> I want to do this job with single SQL query. Is it possible. Pls help.
>
>
> Herewith I am providing the sample data
>
> BR··Light Blue Duck··
> ·0234578···
> BR··Aqua Duck··
> ·0234586···
> UB··Aqua Duck··
>
>
> Regards,
> Omav

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:06 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com