Author |
Topic |
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2013-06-01 : 08:19:02
|
Hello all..please help.I have a table like id name age01 aaa 2201 bbb 3301 ccc 44Now i need to add few data to the table below and make it look likeid name age01 aaa 2201 bbb 3301 ccc 4402 aaa 2202 bbb 3302 ccc 44not sure how to get i used insert into .............select from but did not work??Thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-01 : 20:18:00
|
if your attempt is to replicate the values for id=01 you can use thisINSERT INTO TableSELECT '02',name,ageFROM TableWHERE id = '01' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2013-06-03 : 00:35:06
|
Thanks Visakh,But my intention was not to replicate. but to get the data below 01 ID.It works like INSERT TO.... SELECT FROM..but not sure how to get that??? Thanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-03 : 02:12:56
|
quote: Originally posted by anuraag205 Thanks Visakh,But my intention was not to replicate. but to get the data below 01 ID.It works like INSERT TO.... SELECT FROM..but not sure how to get that??? Thanks
its exactly like what i showed youdid you try it?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-03 : 02:13:27
|
quote: Originally posted by anuraag205 Thanks Visakh,But my intention was not to replicate. but to get the data below 01 ID.It works like INSERT TO.... SELECT FROM..but not sure how to get that??? Thanks
its exactly like what i showed youdid you try it?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2013-06-03 : 03:22:56
|
Yes VIsakh,------------------INSERT INTO [tblsupplierlocation]SELECT [pk_SupplierLocationID],[423],[fk_CountryID],[fk_LocationID],[IsAirport],[IsMeetnGreet],[IsDeskInTermainl],[Description],[IsShutOnHolidays],[Address1],[Address2],[Address3],[City],[State],[PostCode],[ContactEmailID],[ContactPhone],[PublicNote],[PrivateNote],[WorkingHoursSummary],[IsShowOnWebSite],[IsActive],[IsDeleted],[CreateUserID],[CreateDateTime],[UpdateUserID],[UpdatedDateTime]FROM [tblsupplierlocation]WHERE [fk_SupplierID]in (414)----------------------------------------------------and the error shows "Msg 207, Level 16, State 1, Line 2Invalid column name '423'.Msg 8101, Level 16, State 1, Line 2An explicit value for the identity column in table 'tblsupplierlocation' can only be specified when a column list is used and IDENTITY_INSERT is ON.---------------------------------------------------------So could not guess where the error lies...Sorry yaarThanks |
 |
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2013-06-03 : 03:33:25
|
I also tried to update from excelINSERT INTO [tblsupplierlocation]([pk_SupplierLocationID],[fk_SupplierID],[fk_CountryID],[fk_LocationID],[IsAirport],[IsMeetnGreet],[IsDeskInTermainl],[Description],[IsShutOnHolidays],[Address1],[Address2],[Address3],[City],[State],[PostCode],[ContactEmailID],[ContactPhone],[PublicNote],[PrivateNote],[WorkingHoursSummary],[IsShowOnWebSite],[IsActive],[IsDeleted],[CreateUserID],[CreateDateTime],[UpdateUserID],[UpdatedDateTime]) SELECT A.[pk_SupplierLocationID],A.[fk_SupplierID],A.[fk_CountryID],A.[fk_LocationID],A.[IsAirport],A.[IsMeetnGreet],A.[IsDeskInTermainl],A.[Description],A.[IsShutOnHolidays],A.[Address1],A.[Address2],A.[Address3],A.[City],A.[State],A.[PostCode],A.[ContactEmailID],A.[ContactPhone],A.[PublicNote],A.[PrivateNote],A.[WorkingHoursSummary],A.[IsShowOnWebSite],A.[IsActive],A.[IsDeleted],A.[CreateUserID],A.[CreateDateTime],A.[UpdateUserID],A.[UpdatedDateTime]FROM OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=U:\xml AlamoFBL locations sql upload.xls;HDR=YES', 'select * from Sheet') AS A;-------------------------------------------------------------------------------But poped up with error msg Msg 15281, Level 16, State 1, Line 1SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.Thanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-03 : 03:57:25
|
quote: Originally posted by anuraag205 Yes VIsakh,------------------INSERT INTO [tblsupplierlocation]SELECT [pk_SupplierLocationID],[423],[fk_CountryID],[fk_LocationID],[IsAirport],[IsMeetnGreet],[IsDeskInTermainl],[Description],[IsShutOnHolidays],[Address1],[Address2],[Address3],[City],[State],[PostCode],[ContactEmailID],[ContactPhone],[PublicNote],[PrivateNote],[WorkingHoursSummary],[IsShowOnWebSite],[IsActive],[IsDeleted],[CreateUserID],[CreateDateTime],[UpdateUserID],[UpdatedDateTime]FROM [tblsupplierlocation]WHERE [fk_SupplierID]in (414)----------------------------------------------------and the error shows "Msg 207, Level 16, State 1, Line 2Invalid column name '423'.Msg 8101, Level 16, State 1, Line 2An explicit value for the identity column in table 'tblsupplierlocation' can only be specified when a column list is used and IDENTITY_INSERT is ON.---------------------------------------------------------So could not guess where the error lies...Sorry yaarThanks
thats because one of the involved columns (i think pk) is an identity column, so you cant directly insert a value for it ( I would reckon you shouldnt if its a pk)in that case, just ignore that column altogether and do likeINSERT INTO [tblsupplierlocation](all columns except primary key column listed here)SELECT 423,[fk_CountryID],[fk_LocationID],[IsAirport],[IsMeetnGreet],[IsDeskInTermainl],[Description],[IsShutOnHolidays],[Address1],[Address2],[Address3],[City],[State],[PostCode],[ContactEmailID],[ContactPhone],[PublicNote],[PrivateNote],[WorkingHoursSummary],[IsShowOnWebSite],[IsActive],[IsDeleted],[CreateUserID],[CreateDateTime],[UpdateUserID],[UpdatedDateTime]FROM [tblsupplierlocation]WHERE [fk_SupplierID]in (414) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-03 : 04:00:15
|
quote: Originally posted by anuraag205 I also tried to update from excelINSERT INTO [tblsupplierlocation]([pk_SupplierLocationID],[fk_SupplierID],[fk_CountryID],[fk_LocationID],[IsAirport],[IsMeetnGreet],[IsDeskInTermainl],[Description],[IsShutOnHolidays],[Address1],[Address2],[Address3],[City],[State],[PostCode],[ContactEmailID],[ContactPhone],[PublicNote],[PrivateNote],[WorkingHoursSummary],[IsShowOnWebSite],[IsActive],[IsDeleted],[CreateUserID],[CreateDateTime],[UpdateUserID],[UpdatedDateTime]) SELECT A.[pk_SupplierLocationID],A.[fk_SupplierID],A.[fk_CountryID],A.[fk_LocationID],A.[IsAirport],A.[IsMeetnGreet],A.[IsDeskInTermainl],A.[Description],A.[IsShutOnHolidays],A.[Address1],A.[Address2],A.[Address3],A.[City],A.[State],A.[PostCode],A.[ContactEmailID],A.[ContactPhone],A.[PublicNote],A.[PrivateNote],A.[WorkingHoursSummary],A.[IsShowOnWebSite],A.[IsActive],A.[IsDeleted],A.[CreateUserID],A.[CreateDateTime],A.[UpdateUserID],A.[UpdatedDateTime]FROM OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=U:\xml AlamoFBL locations sql upload.xls;HDR=YES', 'select * from Sheet') AS A;-------------------------------------------------------------------------------But poped up with error msg Msg 15281, Level 16, State 1, Line 1SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.Thanks
As error suggests you've to enable the option Ad Hoc Distributed Queries if you want to use OPENROWSET etc. Its disabled by default and can be enbled asEXEC sp_configure 'show advanced option', '1'GORECONFIGURE WITH OVERRIDEGOEXEC sp_configure 'Ad Hoc Distributed Queries', '1'GORECONFIGURE WITH OVERRIDEGO Hopefully you do have the necessary access rights to execute sp_configureMy recommendation would be to use previous method without trying to fetch from excel------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2013-06-03 : 04:30:49
|
GREAT NEWS VISAKH...THIS WORKED...THANKS FOR YOUR SUGGESTIONSINSERT INTO tblsupplierlocation(fk_SupplierID,fk_CountryID,fk_LocationID,IsAirport,IsMeetnGreet,IsDeskInTermainl,Description,isShutOnHolidays,Address1,Address2,Address3,City,State,PostCode,ContactEmailID,ContactPhone,PublicNote,PrivateNote,WorkingHoursSummary,IsShowOnWebSite,IsActive,IsDeleted,createUserID,CreateDateTime,updateUserID,UpdatedDateTime)SELECT 423,[fk_CountryID],[fk_LocationID],[IsAirport],[IsMeetnGreet],[IsDeskInTermainl],[Description],[IsShutOnHolidays],[Address1],[Address2],[Address3],[City],[State],[PostCode],[ContactEmailID],[ContactPhone],[PublicNote],[PrivateNote],[WorkingHoursSummary],[IsShowOnWebSite],[IsActive],[IsDeleted],[CreateUserID],[CreateDateTime],[UpdateUserID],[UpdatedDateTime]FROM [tblsupplierlocation]WHERE [fk_SupplierID]in (414)THIS WORKED...THANKS FOR YOUR SUGGESTIONSThanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-03 : 04:45:07
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|