Home > Archive > MS SQL Server > July 2005 > Query statment question ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Query statment question ?
meyvn77@yahoo.com

2005-07-22, 9:23 am


I have a flat file table that describes crash data in SQL Server.
It contains vehicle information.

I would like to know if anyone knows a SQL statement that could go from
this
table= events

CRASHID | VEH1_TYPE | VEH2_TYPE | VEH_3TYPE
-------------------------------------------
555555 | CAR | TRUCK | VAN

TO

CRASHID | VEH_TYPE | VEH_NUMBER
--------------------------------
555555 CAR 1
555555 Truck 2
555555 VAN 3


Any Ideas? I am relitively new at this and can only see how it could be
done by creating multiple tables and appending them.
Any help that could create the end selection in one query would be
great.

Thanks,
Chuck

Alejandro Mesa

2005-07-22, 9:23 am

Try,

select
crashid,
case t2.c1
when 1 then veh1_type
when 2 then veh2_type
when 3 then veh3_type
end as veh_type,
t2.c1 as veh_number
from
t1
cross join
(
select cast(1 as int) as c1
union all
select cast(2 as int) as c1
union all
select cast(3 as int) as c1
) as t2
go


AMB

"meyvn77@yahoo.com" wrote:

>
> I have a flat file table that describes crash data in SQL Server.
> It contains vehicle information.
>
> I would like to know if anyone knows a SQL statement that could go from
> this
> table= events
>
> CRASHID | VEH1_TYPE | VEH2_TYPE | VEH_3TYPE
> -------------------------------------------
> 555555 | CAR | TRUCK | VAN
>
> TO
>
> CRASHID | VEH_TYPE | VEH_NUMBER
> --------------------------------
> 555555 CAR 1
> 555555 Truck 2
> 555555 VAN 3
>
>
> Any Ideas? I am relitively new at this and can only see how it could be
> done by creating multiple tables and appending them.
> Any help that could create the end selection in one query would be
> great.
>
> Thanks,
> Chuck
>
>

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com