As others have said, you cannot alias the name as part of the INSERT INTO statement. You would need to put it in the subquery in the WHERE statement.
The aliases are mandatory for inline queries (queries embedded within another statement) as a data source to qualify the columns in a select list.
Alias is used to give a temporary name(only for the duration of the query) to the column or table in order to make the column name or table name more readable. It does not change the name of the column permanently.
SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. An alias only exists for the duration of that query. An alias is created with the AS keyword.
I saw above question in one of the blogs. But couldn't find the answer anywhere. Maybe SQL Server experts here can help me on this.
CREATE TABLE #DEMO (VALUE1 INT, VALUE2 VARCHAR(10))
CREATE TABLE #DEMO1 (VALUE1 INT, VALUE2 VARCHAR(10))
INSERT INTO #DEMO VALUES (1, '10')
INSERT INTO #DEMO1 (a.a.a.value1,b.b.b.value2)
SELECT
Value1, Value2
FROM #DEMO
If you see the insert statement, I have specified some alias name in the inserted columns. To my wonder, SQL Server didn't throw any error while executing the statement. What's the reason behind this? Could anyone help?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With