Solved

cannot create table from data

Posted on 2007-12-03
3
166 Views
Last Modified: 2010-03-20
I am having trouble creating a new table that is populated from the data from the query. help would be appreciated
regards in advance
select
		 vehicle_id ,
		 MAX(case when [schema_id]=101 then data_value else NULL end) AS UniqueId , 105 AS ReasonValue,
		 MAX(case when [schema_id]=105 then data_value else NULL end) AS ReasonCode,
		 MAX(case when [schema_id]=108 then data_value else NULL end) AS Yr, 110 AS CountryValue,
		 Max(case when [schema_id]=110 then data_value else NULL end) AS CountryCode,
		 MAX(case when [schema_id]=115 then data_value else NULL end) AS VersionIntro,
		 MAX(case when [schema_id]=125 then data_value else NULL end) AS IntroDate, 
                 MAX(case when [schema_id]=128 then data_value else NULL end) AS Make,
		 MAX(case when [schema_id]=129 then data_value else NULL end) AS Model,
		 MAX(case when [schema_id]=130 then data_value else NULL end) AS ModelDesc,
		 MAX(case when [schema_id]=131 then data_value else NULL end) AS Variant,
		 MAX(case when [schema_id]=302 then data_value else NULL end) AS Version, 
                 MAX(case when [schema_id]=602 then data_value else NULL end) AS Doors, 603 AS BodyValue,
		 MAX(case when [schema_id]=603 then data_value else NULL end) AS BodyCode, 606 AS RoofValue,
		 MAX(case when [schema_id]=606 then data_value else NULL end) AS RoofCode, 608 AS WheelbaseValue,
		 MAX(case when [schema_id]=608 then data_value else NULL end) AS WheelbasCode,
		 MAX(case when [schema_id]=702 then data_value else NULL end) AS Seats,
		 MAX(case when [schema_id]=6502 then data_value else NULL end) AS DriveType, 
                 MAX(case when [schema_id]=7402 then data_value else NULL end) AS CC,
		 MAX(case when [schema_id]=7407 then data_value else NULL end) AS Cyl,
		 MAX(case when [schema_id]=7408 then data_value else NULL end) AS EngineConfig, 7414 AS ValveGearValue,
		 MAX(case when [schema_id]=7414 then data_value else NULL end) AS ValveGearCode, 
                 MAX(case when [schema_id]=7417 then data_value else NULL end) AS Valves,
		 MAX(case when [schema_id]=7502 then data_value else NULL end) AS Compressor, 8702 AS FuelVlaue, 
                 MAX(case when [schema_id]=8702 then data_value else NULL end) AS FuelCode, 8703 AS AltFuelValue,
		 MAX(case when [schema_id]=8703 then data_value else NULL end) AS AltFuelCode, 
	         MAX(case when [schema_id]=20602 then data_value else NULL end) AS Trans,
		 MAX(case when [schema_id]=20603 then data_value else NULL end) AS Gears,
		 MAX(case when [schema_id]=15304 then data_value else NULL end) AS BHP,
		 MAX(case when [schema_id]=15303 then data_value else NULL end) AS Kw
FROM         Jato.dbo.equipment
GROUP BY vehicle_id, ReasonValue, CountryValue, BodyValue, RoofValue, WheelbaseValue, ValveGearValue, FuelVlaue, AltFuelValue

Open in new window

0
Comment
Question by:PeterBaileyUk
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 20394710
Eg:


Select Col1 , col2
INTO <NewTableName>
from someExisitingTable
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20394714
Try this and change the table name after into. I had given equipmentcounts as new tablename

select
		 vehicle_id ,
		 MAX(case when [schema_id]=101 then data_value else NULL end) AS UniqueId , 105 AS ReasonValue,
		 MAX(case when [schema_id]=105 then data_value else NULL end) AS ReasonCode,
		 MAX(case when [schema_id]=108 then data_value else NULL end) AS Yr, 110 AS CountryValue,
		 Max(case when [schema_id]=110 then data_value else NULL end) AS CountryCode,
		 MAX(case when [schema_id]=115 then data_value else NULL end) AS VersionIntro,
		 MAX(case when [schema_id]=125 then data_value else NULL end) AS IntroDate, 
                 MAX(case when [schema_id]=128 then data_value else NULL end) AS Make,
		 MAX(case when [schema_id]=129 then data_value else NULL end) AS Model,
		 MAX(case when [schema_id]=130 then data_value else NULL end) AS ModelDesc,
		 MAX(case when [schema_id]=131 then data_value else NULL end) AS Variant,
		 MAX(case when [schema_id]=302 then data_value else NULL end) AS Version, 
                 MAX(case when [schema_id]=602 then data_value else NULL end) AS Doors, 603 AS BodyValue,
		 MAX(case when [schema_id]=603 then data_value else NULL end) AS BodyCode, 606 AS RoofValue,
		 MAX(case when [schema_id]=606 then data_value else NULL end) AS RoofCode, 608 AS WheelbaseValue,
		 MAX(case when [schema_id]=608 then data_value else NULL end) AS WheelbasCode,
		 MAX(case when [schema_id]=702 then data_value else NULL end) AS Seats,
		 MAX(case when [schema_id]=6502 then data_value else NULL end) AS DriveType, 
                 MAX(case when [schema_id]=7402 then data_value else NULL end) AS CC,
		 MAX(case when [schema_id]=7407 then data_value else NULL end) AS Cyl,
		 MAX(case when [schema_id]=7408 then data_value else NULL end) AS EngineConfig, 7414 AS ValveGearValue,
		 MAX(case when [schema_id]=7414 then data_value else NULL end) AS ValveGearCode, 
                 MAX(case when [schema_id]=7417 then data_value else NULL end) AS Valves,
		 MAX(case when [schema_id]=7502 then data_value else NULL end) AS Compressor, 8702 AS FuelVlaue, 
                 MAX(case when [schema_id]=8702 then data_value else NULL end) AS FuelCode, 8703 AS AltFuelValue,
		 MAX(case when [schema_id]=8703 then data_value else NULL end) AS AltFuelCode, 
	         MAX(case when [schema_id]=20602 then data_value else NULL end) AS Trans,
		 MAX(case when [schema_id]=20603 then data_value else NULL end) AS Gears,
		 MAX(case when [schema_id]=15304 then data_value else NULL end) AS BHP,
		 MAX(case when [schema_id]=15303 then data_value else NULL end) AS Kw
FROM Jato.dbo.equipment
Into equipmentcounts
GROUP BY vehicle_id, ReasonValue, CountryValue, BodyValue, RoofValue, WheelbaseValue, ValveGearValue, FuelVlaue, AltFuelValue
 

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 20394801
it said incorrect syntax near the keyword into but we cannot see why
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help Parsing a String with SQL Syntax 23 42
SQL Sub-Query Help 22 62
SQL: launch actions one before the other 10 22
ServiceCenter IR Query Expressions 1 15
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question