SQL Query invalid object name issues when using variable - sql

Msg 208, Level 16, State 1, Line 1
Invalid object name 'events'.
select count(distinct(games)) from events

The error message is about that the events table cannot be found. So, please ensure that:
this is the table name
you have access to this table
It will be better to add the schema. For example, sales.events. It is possible that the table is not in your user default schema.

Related

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.

Getting Invalid Column Name in Azure SQL Data Warehouse

I created an alias and checked whether alias column is null or not null but alias is not working in sql data warehouse.
select (emp_id) a
from dbo.test b
where a is not null
Msg 207, Level 16, State 1, Line 1
Invalid column name 'a'.
You can't Use alias as simple as in where clause. But there are other ways which you can implement it
Using CTE
CROSS APPLY/OUTER APPLY
There are good examples at here for you to look-out

Select row in SQL using GUID

When creating the table I used
[Key] UNIQUEIDENTIFIER not null DEFAULT NEWSEQUENTIALID(),
I'm trying to use the following to select, I gave up on doing it in C# for now and am entering the query in MyLittleAdmin (the SQL database manager my hosting provider is using)
SELECT *
FROM GameList
WHERE Key = '9abc2cdc-1919-e611-80d3-008cfa5ae917'
I get the following error:
Msg 156, Level 15, State 1, Line number 1
Incorrect syntax near the keyword 'Key'.
I know I have the right GUID, using SELECT * FROM GameList returns the data and I have copied and pasted from it.
Key is a keyword and must be surroundted by string identifiers if you want to use it as a column name (like it is in the column definition):
SELECT *
FROM GameList
WHERE [Key] = '9abc2cdc-1919-e611-80d3-008cfa5ae917'

Can a fake table be created in SQL Server 2005

I would like to know if it is possible to create a fake table in SQL Server 2005.
Because when I tried I got an error
Msg 208, Level 16, State 1, Line 1
Invalid object name 'dual'.
This is what I tried
and it did not work. For test purpose I have created a test table to execute the query.
In SQL Server you are allowed to leave out the FROM clause. So you don't need a fake table.
Instead of writing
select 42
from dual;
just write
select 42;

Use dbo.table SQL Server error

I have a database, and I am importing a big table...
When I try to execute a stored procedure I have no success, to check I do something simple like:
select * from tableAT;
but the tableAT is marked as error (even when it appears in the Object explorer window),
Msg 208, Level 16, State 1, Line 1
Invalid object name 'tableAT'.
but if I do right click and select the icon of the table and select
SELECT TOP 1000 ROWS
a result is coming and the query shown is
SELECT TOP 1000 [1]
,[2], etc...
FROM [DB_NAME].[dbo].[tableAT]
if I change the way I am calling the store procedure to
exec procedureA [DB_NAME].[dbo].[tableAT]
I get error as if the table does not exist?
Do you know why could this be error?
A size issue, I already incremented the database initial size files...
You must be logged in as admin user to select from this table. Because it is created for dbo. Or you should have proper rights
Make sure you've set up your table valued parameter correctly: here's an example.