| Author |
Topic |
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 09:20:25
|
| HiI am using SQl 2005 and i am generating script with right click on table than "script table as" than "UPDATE table to" ... i than i copy my results to another computer where i am running sql express 2005... but i get this error:Msg 102, Level 15, State 1, Line 2Incorrect syntax near '<'.UPDATE [MYTable].[dbo].[tableTEST] SET [name_column] = <name_column, varchar(16),>,[name_column2] = <name_column2, varchar(16),>,[name_column3] = <name_column3, varchar(16),>,[name_column4] = <name_column4, varchar(16),>,[name_column5] = <name_column5, varchar(16),> WHERE <Search Conditions,,> |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 09:26:27
|
| you need to replace <name_column, varchar(16),>,<Search Conditions,,> etc place holders with actual values |
 |
|
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 09:32:12
|
| ? hmm i changed from actual values to this "name_column" only for this forum (privat reasons)... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 09:37:47
|
| any ways you dont need < bits what you need is convert(name_column, varchar(16)) instead |
 |
|
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 09:48:33
|
| Ok, but now i have new error:Msg 102, Level 15, State 1, Line 2Incorrect syntax near ','.UPDATE [MYTable].[dbo].[tableTEST]SET [name_column] = (name_column, varchar(16)),[name_column2] = (name_column2, varchar(16)),[name_column3] = (name_column3, varchar(16)),[name_column4] = (name_column4, varchar(16)),[name_column5] = (name_column5, varchar(16))WHERE <Search Conditions,,> |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 09:49:21
|
quote: Originally posted by newSqlMan Ok, but now i have new error:Msg 102, Level 15, State 1, Line 2Incorrect syntax near ','.UPDATE [MYTable].[dbo].[tableTEST]SET [name_column] = (name_column, varchar(16)),[name_column2] = (name_column2, varchar(16)),[name_column3] = (name_column3, varchar(16)),[name_column4] = (name_column4, varchar(16)),[name_column5] = (name_column5, varchar(16))WHERE <Search Conditions,,>
where's convert ? please use the query as suggested |
 |
|
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 09:53:42
|
| UPDATE [MYTable].[dbo].[tableTEST]So u mean like that?SET [name_column] = convert(name_column, varchar(16)),[name_column2] = convert(name_column2, varchar(16)),[name_column3] = convert(name_column3, varchar(16)),[name_column4] = convert(name_column4, varchar(16)),[name_column5] = convert(name_column5, varchar(16))WHERE <Search Conditions,,> |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 09:57:27
|
quote: Originally posted by newSqlMan UPDATE [MYTable].[dbo].[tableTEST]So u mean like that?SET [name_column] = convert(name_column, varchar(16)),[name_column2] = convert(name_column2, varchar(16)),[name_column3] = convert(name_column3, varchar(16)),[name_column4] = convert(name_column4, varchar(16)),[name_column5] = convert(name_column5, varchar(16))WHERE <Search Conditions,,>
exactly and obviously you need to replace the last bit (<Search Conditions,,>)with actual conditions |
 |
|
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 10:17:22
|
| New error: 'varchar' is not a recognized built-in function name. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 10:19:40
|
quote: Originally posted by newSqlMan New error: 'varchar' is not a recognized built-in function name.
i dont think you're using ms sql server then. |
 |
|
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 10:21:04
|
| i am using sql express 2005 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 10:24:12
|
quote: Originally posted by newSqlMan i am using sql express 2005
oops just notice i had them other way around. it should beconvert( varchar(16),name_column) |
 |
|
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 10:31:22
|
| The name "column_name" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 10:34:42
|
quote: Originally posted by newSqlMan The name "column_name" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
actually can i ask what you're attempting with above query? |
 |
|
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 10:41:33
|
| i am trying to copy 1 table scheme from PC-1 (only structure with no data) and than copy it to another sql table on Pc-2.So if i add new column in PC-1 ... i need to copy(update) this new column also to pc-2i thought that i could do that with simple script... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 10:45:24
|
quote: Originally posted by newSqlMan i am trying to copy 1 table scheme from PC-1 (only structure with no data) and than copy it to another sql table on Pc-2.So if i add new column in PC-1 ... i need to copy(update) this new column also to pc-2i thought that i could do that with simple script...
nope you cant add columns with update. update is a dml stmt which does data update. what you need is alter table ddl script which adds the new reqd columns. |
 |
|
|
newSqlMan
Starting Member
11 Posts |
Posted - 2010-01-24 : 10:48:34
|
| how can i do that... is there any free simple ddl script? |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-01-24 : 13:13:23
|
| [code]ALTER TABLE MyTableName ADD NewColumnName varchar(10) NULL[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-24 : 13:28:18
|
in your case if you want new columns to be based on another table then you can generate script like below and then view results as text and copy and paste it to new window execute to create new columnsSELECT 'ALTER yourdesttable ADD ' + column_name + ISNULL( ' (' + DATA_TYPE+ ') ','') + CASE WHEN IS_NULLABLE = 'Yes' THEN ' NULL' ELSE ' NOT NULL' ENDFROM information_schema.columns where table_name='Yoursourcetable' |
 |
|
|
|