How to drop the column name which contain dot - sql

Using SQL server 2008
column name is : file.retry
I want to drop the column file.retry. while running the below query getting the exception
ALTER TABLE FILEQ DROP COLUMN file.retry
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '.'.
How to solve this issue. Any one can help please

Surround file.retry in square brackets like so [file.retry] to avoid the interpreter trying to parse it as a table.column identifier.
ALTER TABLE FILEQ DROP COLUMN [file.retry]

Use square brackets around the column name
ALTER TABLE FILEQ DROP COLUMN [file.retry]

Related

Moving a table from one schema to another in Exasol

I am trying to move a table which resides in a certain schema to a different schema with the same table name. I have tried the following but they do not work:
rename <OLD_SCHEMA_NAME>.<TABLE_NAME> TO <NEW_SCHEMA_NAME>.<TABLE_NAME>;
The error that appears is:
SQL Error [42000]: invalid identifier chain for new name [line 1, column 100] (Session: 1722923178259251200)
and
ALTER TABLE <OLD_SCHEMA_NAME>.<TABLE_NAME> RENAME <NEW_SCHEMA_NAME>.<TABLE_NAME>;
The error that appears is:
SQL Error [42000]: syntax error, unexpected IDENTIFIER_PART_, expecting COLUMN_ or CONSTRAINT_ [line 1, column 62] (Session: 1722923178259251200)
Many Thanks!
According to Exasol documentation there is no way to move table between schemas using RENAME statement:
Schema objects cannot be shifted to another schema with the RENAME
statement. For example, 'RENAME TABLE s1.t1 TO s2.t2' is not allowed.
I would move the table this way:
create table <NEW_SCHEMA_NAME>.<TABLE_NAME>
like <OLD_SCHEMA_NAME>.<TABLE_NAME>
including defaults
including identity
including comments;
insert into <NEW_SCHEMA_NAME>.<TABLE_NAME>
select *
from <OLD_SCHEMA_NAME>.<TABLE_NAME>;
drop table <OLD_SCHEMA_NAME>.<TABLE_NAME>;

Change SSRS parameter value into column name in query

I am trying to, without stored procedures, create a SQL query in an SSRS report and take a parameter value and use it as a column name. My question is how to I change the parameter value into the actual column name? I have tried the following query with the table identifier (i.e. t.#FilterColumn1) and without the table identifier (i.e. #FilterColumn1).
DECLARE #FilterColumn1 AS nvarchar(250)
SET #FilterColumn1 = 'Column1'
SELECT DISTINCT
t.#FilterColumn1
FROM [JetNavDwh2017].[dbo].[TableName] t WITH(NOLOCK)
When I do not use the table identifier the result is the the column name I defined. When I use the table identifier I receive the error message below, but I have not found a conclusive way to resolve the issue based on the error. Thank you in advance for your help!
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '#FilterColumn1'.
Msg 319, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

MariaDB unable to drop column named "`"

Not sure how this happened, but a column got created named: "`". (just the back tick). When I attempt to drop this column, I end up with a syntax error.
Outside of taking a SQL dump and fixing the dump in a text editor, Does anybody have a suggestion to fix this query?
ALTER TABLE tableName DROP COLUMN "`";
You need to escape the inner backtick with another backtick, so:
alter table tableName drop column ````;

Error while trying to mask a column in SSMS

I'm trying to mask some information in my table, when I use this :
ALTER TABLE Person
ALTER COLUMN DoB add masked with (Function = 'default()')
I get those two error :
Incorrect syntax near the word 'masked'
and
Incorrect syntax near the keyword 'with'. If the statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
That's literally the same code as the Microsoft documentation, but for some reason it doesn't work
If somebody could explain me what is the problem, that would help me a lot
To mask a column using the ALTER statement the datatype of the column must be included in this statement. The ADD keyword is also not necessary. I don't know what the datatype of the DoB column from your example is but it will need to be changed as below. From the name I'm guessing this is a datetime column, but if it's not the matching datatype will need to be substituted in.
ALTER TABLE Person ALTER COLUMN DoB DATETIME MASKED WITH (FUNCTION = 'default()')
Update:
This error was a result of using SQL Server 2012 when this feature was released in SQL Server 2016.

Select syntax as a subquery to insert into

Here's what I'm trying to do in SQL Query Analyzer.
Insert into db_name1.dbo.tb_name1 (select * from db_name2.dbo.tb_name2)
but I keep getting this error message
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'select'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.
I wonder what went wrong. Does subquery isn't work in SQL server 2000?
What is the right syntax for this one? I would like to transfer all the values from a tables column of a database to another table of another database without creating any duplicate of its element but merely overwrites the current values.
This is your query as you think it should be interpeted:
Insert into db_name1.dbo.tb_name1
(select * from db_name2.dbo.tb_name2)
This is the query as the compiler sees it:
Insert into db_name1.dbo.tb_name1(select * from db_name2.dbo.tb_name2)
That is, the open parenthese after the table name means "the list of columns is starting here". But you don't have a list of columns. And select is not a valid column name. Hence the error.
This is easily fixed by removing the parentheses:
Insert into db_name1.dbo.tb_name1
select * from db_name2.dbo.tb_name2
However, it is more correct to include the column names being inserted:
Insert into db_name1.dbo.tb_name1(col1 . . .)
select * from db_name2.dbo.tb_name2;
It is a good idea to always include column names in insert statements. If you had done this, you wouldn't have had to ask this question.