Author |
Topic |
fahim1234
Starting Member
7 Posts |
Posted - 2011-01-05 : 07:20:09
|
INSERT INTO LOCATION_DIM (SELECT COLUMN1 FROM SPREADSHEET3 WHERE LOCATION_ID = '409',SELECT 'West Yorkshire' FROM COLUMN1 ,SELECT 'Leeds' FROM COLUMN1 );COULD U PLEASE HELP AND TELL WHY THIS CODE IS NOT WORKING...I AM TRYING TO SELECT 3 THING FROM 1 COLUMN IN A TABLETHANKS FOR UR HELP |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-05 : 07:24:36
|
Please don't post in all caps. It's like shouting at us.Please, please, please open up books online and look at the syntax and examples of Insert. It's clear you have no idea what the valid syntax is and guessing is not going to work.As I said on your other insert thread, the valid forms of insert areInsert into <table> (<Destination column list>)Values (...)and Insert into <table> (<Destination column list>)select <columns> from ...You can't mix and match the two and expect it to work.--Gail ShawSQL Server MVP |
|
|
fahim1234
Starting Member
7 Posts |
Posted - 2011-01-05 : 07:51:02
|
thanks for your help , sorry wasnt shouting,i am not using values anymore , im only using select statements... can you use more than 1 select statement in 1 insert statement to select from 1 columntyutyu |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-05 : 07:56:12
|
You're still mixing the forms. Look at the two styles I described. Look where the brackets are.Have you read through the syntax and examples on INSERT in books online? Books Online is the help file included with SQL. Press F1 in management studio to open Books Online.Also look up the syntax for a select statement. It's SELECT <columns> FROM <Table>, not SELECT <String values> FROM <Column>Finally, I don't think you even need three selects. If I'm guessing correctly what you're trying to do, you need one select. Start by writing a single select statement that returns the data that you want to insert.--Gail ShawSQL Server MVP |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-05 : 08:07:22
|
Did you know that SELECT 'Leeds' FROM COLUMN1 will give the value 'Leeds' as many times as there are rows in the table?. Post some sample data from the table with expected result to be added to the table LOCATION_DIMMadhivananFailing to plan is Planning to fail |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-05 : 08:16:52
|
quote: Originally posted by madhivanan Did you know that SELECT 'Leeds' FROM COLUMN1 will give the value 'Leeds' as many times as there are rows in the table?.
More likely I think it will giveMsg 208, Level 16, State 1, Line 1Invalid object name 'COLUMN1'.Since n earlier select references Column1 as a column in table SPREADSHEET3--Gail ShawSQL Server MVP |
|
|
fahim1234
Starting Member
7 Posts |
Posted - 2011-01-05 : 08:51:14
|
thankew people your helping but its not helptyutyu |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-05 : 08:56:59
|
quote: Originally posted by fahim1234 thankew people your helping but its not helptyutyu
You need to give us more informations.Do these give any errors?SELECT 'West Yorkshire' FROM COLUMN1 SELECT 'Leeds' FROM COLUMN1MadhivananFailing to plan is Planning to fail |
|
|
fahim1234
Starting Member
7 Posts |
Posted - 2011-01-05 : 09:10:31
|
EDIT LOCATION_ID COLUMN1 COLUMN2409 Yorkshire & Humberside 12334419 Richmondshire 123420 Ryedale 89421 Scarborough 5864422 Selby 271423 York 870428 Sheffield "2,469"429 West Yorkshire "17,483"430 Bradford "4,075"431 Calderdale "1,219"432 Kirklees "2,589"433 Leeds "7,391"the spreasheet table looks a bit like this .. what i want is to select 'yorkshire & humberside', 'west yorkshire' and 'leeds' and put them 3 in a new table which is location_dim. im having trouble doing that ... could you please help and tell me how i can select those 3 data and put it in a new table please |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-05 : 09:13:01
|
I will repeat the advice I gave in an earlier post:Start by writing a single select statement that returns the data that you want to insert. Can you do that?--Gail ShawSQL Server MVP |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-05 : 09:46:09
|
Start with thisSELECT COLUMN1 from spreasheet WHERE COLUMN1 in ('yorkshire & humberside', 'west yorkshire' ,'leeds' )MadhivananFailing to plan is Planning to fail |
|
|
|