Quotation mark in column name - Invalid column name - sql-server

I am using SQL server 2017 and having a problem with the double quotation marks in columns' names
The query I used is like this:
insert into torque_value.value_table("ID","value","timestamp") values ('111','1111',convert(datetime,'2017-12-12T00:34:00.000'))
which worked well in SQL Server management studio but did not work at all in sqlcmd and it returned error
Msg 207, Level 16, State 1, Server USER\SQLEXPRESS, Line 1
Invalid column name 'ID'.
Msg 207, Level 16, State 1, Server USER\SQLEXPRESS, Line 1
Invalid column name 'value'.
Msg 207, Level 16, State 1, Server USER\SQLEXPRESS, Line 1
Invalid column name 'timestamp'.
Is the syntax in the sqlcmd different from in SSMS ? How should I handle this kind of error ?

Related

Microsoft SQL server 2016, cannot create sequence

I have Microsoft SQL server 2016, I am using SSMS to do my DB work. I am trying to create sequences and I keep getting this error
CREATE SEQUENCE dbo.seq_changeid As int START WITH 1 INCREMENT BY 1;
Error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'SEQUENCE'.
Msg 319, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
I have tried it in SQLCMD and it does not work there as well. This is local database that i am using for some testing. I login using SQL Server Authentication.
I even tried select * from sys.sequences and it errors
Msg 208, Level 16, State 1, Line 10
Invalid object name 'sys.sequences'

insert into select, working with two tables from different servers error

My code:
INSERT INTO lclTabla
SELECT *
FROM openquery([LD_DB_A0FCCD_ALDOLANCHO],
'SELECT *
FROM [DB_A0FCCD_aldolancho].[dbo].[servTable]')
WHERE
lclTabla.dni = [LD_DB_A0FCCD_ALDOLANCHO].[DB_A0FCCD_aldolancho].[dbo].[servTable].[dni]
is causing an error:
Msg 4104, Level 16, State 1, Line 17
The multi-part identifier "lclTabla.dni" could not be bound.
Msg 4104, Level 16, State 1, Line 17
The multi-part identifier "LD_DB_A0FCCD_ALDOLANCHO.DB_A0FCCD_aldolancho.dbo.servTable.dni" could not be bound.
I want to insert where the id from local table is the same in the server table
Please help!!! In T-SQL
Whenever you run cross server query, You must follow proper naming convention
i.e. [server name].[database name].[schema name].[table name]
In your query, I can see wrong naming convention in -
"[LD_DB_A0FCCD_ALDOLANCHO].[DB_A0FCCD_aldolancho].[dbo].[servTable].[dni]"

AdventureWorks activation error in SQL Server, I don't know if it is my pathway is wrong or my database is wrong

I'm trying to add AdventureWorks to my SQL Server 2014 Management Studio. After I opened the query in SQLCMD code, I changed the setvar path to my server name.
How do I fix this error?
I have the following error message:
Started - 2016-07-09 00:32:33.533
*** Dropping Database
*** Creating Database
Msg 5133, Level 16, State 1, Line 89
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL12.DACHENMCIS\MSSQL\DATA\AdventureWorksDW2014_Data.mdf" failed with the operating system error 3(The system cannot find the path specified.).
Msg 1802, Level 16, State 1, Line 89
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
*** Checking for AdventureWorksDW2014 Database
*** AdventureWorksDW2014 Database does not exist. Make sure that the script is being run in SQLCMD mode and that the variables have been correctly set.
Msg 911, Level 16, State 1, Line 119
Database 'AdventureWorksDW2014' does not exist. Make sure that the name is entered correctly.
Msg 208, Level 16, State 1, Procedure vDMPrep, Line 1683
Invalid object name 'dbo.FactInternetSales'.
Msg 208, Level 16, State 1, Procedure vTimeSeries, Line 1731
Invalid object name 'dbo.vDMPrep'.
Msg 208, Level 16, State 1, Procedure vTargetMail, Line 1796
Invalid object name 'dbo.DimCustomer'.
Msg 208, Level 16, State 1, Procedure vAssocSeqOrders, Line 1828
Invalid object name 'dbo.vDMPrep'.
Add privileges to "C:\Program Files\Microsoft SQL Server\MSSQL12.DACHENMCIS\MSSQL\DATA\", you don't have all required.
Or if possibly the path is not valid, Replace "C:\Program Files\Microsoft SQL Server\MSSQL12.DACHENMCIS\MSSQL\DATA\" with an existing folder path on which you have full privileges and you'll be fine.

Can not able to take back up get error Msg 3201, Level 16, State 1, Line 1

I am practicing to create procedure which take back up of all data base except system database using Dynamic SQL my procedure compile successfully but when i run it i get below error for each data base
Msg 3201, Level 16, State 1, Line 1 Cannot open backup device
'F:\DHAVAL_BACKUP_DEMO\itmusket_StudentApp_2015_05_31_10:27:07.BAK'.
Operating system error 123(The filename, directory name, or volume
label syntax is incorrect.). Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
I have also change my default database back up path by taking reference of this
here is my database setting snap
please suggest me way to overcome this problem..
A file name with : is invalid, change them to ;.
#SQL = '.....' + REPLACE(#BackupPath, ':', ';') + '....'

MS SQL server 2005 - Error while querying with a column name as key

I have a table with a column name as "key". I am unable to filter based on that column
select * from myTable where key='someVal'
I get the following error
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'key'.
I cannot change the column name. How I can circumvent this issue?
It's because key is a keyword. If you have keywords as object names, you need to put them in brackets:
select * from myTable where [key]='someVal'

Resources