I continually receive these errors when I try to do a select with linked server on other tables. I end up rewriting the query, changing the order of joins, modifying some groups and then it works at the end, but I can not understand it.
SELECT TOP (100) PERCENT [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_COGNOME + ' ' + [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_NOME AS UTENTE, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.TELEFONI.S_TEL AS TEL,
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.SEDI.S_DESCR AS PIANO, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_QT AS NETNAME, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.EMAIL.S_EMAIL AS EMAIL,
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_DOMINIO AS DOMINIO, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.UFFICI.S_DESCR AS SERVIZIO, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.AZIENDE.S_DESCR AS AZIENDA
FROM [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.AZIENDE RIGHT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.EMAIL RIGHT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA ON [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.EMAIL.ID_UTENTE = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.INCID LEFT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.SEDI ON [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.ID_SEDE = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.SEDI.INCID LEFT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.TELEFONI ON [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.INCID = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.TELEFONI.ID_UTENTE LEFT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.UFFICI ON [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.ID_UFFICIO = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.UFFICI.INCID ON
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.AZIENDE.INCID = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.ID_AZIENDA
ORDER BY [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_COGNOME, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_NOME
GO
Msg 4104, Level 16, State 1, Line 18 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.EMAIL.ID_UTENTE" could not be
bound.
Msg 4104, Level 16, State 1, Line 18 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.INCID" could not be
bound.
Msg 4104, Level 16, State 1, Line 19 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.ID_SEDE" could not be
bound.
Msg 4104, Level 16, State 1, Line 19 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.SEDI.INCID" could not be bound.
Msg 4104, Level 16, State 1, Line 20 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.INCID" could not be
bound.
Msg 4104, Level 16, State 1, Line 20 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.TELEFONI.ID_UTENTE" could not be
bound.
Msg 4104, Level 16, State 1, Line 21 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.ID_UFFICIO" could not
be bound.
Msg 4104, Level 16, State 1, Line 21 The multi-part
identifier "ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.UFFICI.INCID" could
not be bound.
Msg 4104, Level 16, State 1, Line 22 The multi-part
identifier "ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.AZIENDE.INCID" could
not be bound.
Msg 4104, Level 16, State 1, Line 22 The multi-part
identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.ID_AZIENDA" could not
be bound.
Msg 4104, Level 16, State 1, Line 13 The multi-part
identifier "ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_COGNOME"
could not be bound.
Msg 4104, Level 16, State 1, Line 13 The
multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_NOME" could not be
bound.
Msg 4104, Level 16, State 1, Line 13 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.TELEFONI.S_TEL" could not be
bound.
Msg 4104, Level 16, State 1, Line 14 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.SEDI.S_DESCR" could not be
bound.
Msg 4104, Level 16, State 1, Line 14 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_QT" could not be
bound.
Msg 4104, Level 16, State 1, Line 14 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.EMAIL.S_EMAIL" could not be
bound.
Msg 4104, Level 16, State 1, Line 15 The multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_DOMINIO" could not
be bound.
Msg 4104, Level 16, State 1, Line 15 The multi-part
identifier "ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.UFFICI.S_DESCR" could
not be bound.
Msg 4104, Level 16, State 1, Line 15 The multi-part
identifier "ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.AZIENDE.S_DESCR"
could not be bound.
Msg 4104, Level 16, State 1, Line 23 The
multi-part identifier
"ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_COGNOME" could not
be bound.
Msg 4104, Level 16, State 1, Line 23 The multi-part
identifier "ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_NOME"
could not be bound.
Disclaimer: This is not a solution to your problem, but it's a major step on getting there.
The error you get means that SQL Server can't find the identifiers you specified in your query. Since every identifier in your original query is a multi part identifier, it's hard to read and harder to debug, so I've aliased all your tables to simplify the query you posted.
Also, mixing left joins with right joins is a recipe for disaster, so I did my best to fix that. This query should not get rid of all the error messages you've got but it should minimize them and help you find the problems.
Also, I've removed the TOP 100 PERCENT and ORDER BY clause. See my comment for details.
So here is the simplified query, I hope it helps.
SELECT ANAGRAFICA.S_COGNOME + ' ' +
ANAGRAFICA.S_NOME AS UTENTE,
TELEFONI.S_TEL AS TEL,
SEDI.S_DESCR AS PIANO,
ANAGRAFICA.S_QT AS NETNAME,
EMAIL.S_EMAIL AS EMAIL,
ANAGRAFICA.S_DOMINIO AS DOMINIO,
UFFICI.S_DESCR AS SERVIZIO,
AZIENDE.S_DESCR AS AZIENDA
FROM [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.AZIENDE As AZIENDE
RIGHT JOIN
(
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA As ANAGRAFICA
LEFT JOIN [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.EMAIL As EMAIL ON EMAIL.ID_UTENTE = ANAGRAFICA.INCID
LEFT JOIN [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.SEDI As SEDI ON ANAGRAFICA.ID_SEDE = SEDI.INCID
LEFT JOIN [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.TELEFONI As TELEFONI ON ANAGRAFICA.INCID = TELEFONI.ID_UTENTE
LEFT JOIN [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.UFFICI As UFFICI ON ANAGRAFICA.ID_UFFICIO = UFFICI.INCID
) ON AZIENDE.INCID = ANAGRAFICA.ID_AZIENDA
Related
The picture shows the table schema:
The line reported an error when querying the data:
select *,bBands(close, 5, 2, 2, 0) as `high`mid`low from kline
The error message is:
The calculated column was not initialized or an exception was raised.
However, another script I tried didn't report the error:
close = 7.2 6.97 7.08 6.74 6.49 5.9 6.26 5.9 5.35 5.63 3.81 3.935 4.04 3.74 3.7 3.33 3.64 3.31 2.69 2.72
date = (2020.03.02 + 0..4 join 7..11).take(20)
symbol = take(`F,10) join take(`GPRO,10)
t = table(symbol, date, close)
select *, bBands(close, 5, 2, 2, 2) as `high`mid`low from t context by symbol
Why the error occurs and how can I avoid it in my code?
This error is raised because the names of the columns coincide with UP and DN of the Bollinger Bands.
You can use the following code:
select *,bBands(close, 5, 2, 2, 0) as `bBand_high`mid`bBand_low from kline.
I'm trying to delete a table named DBA.[ in Sybase IQ database. This is a wrong table which is not desired so we need to delete it. I've tried several options but not successful. Please share any workaround to drop the table, if anyone knows.
iqisql -Udba -P*** -Sdwhdb -w500
1> drop table dba.[
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near '
' on line 2
1> drop table dba.[[]
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near '[[' on line 1
1> drop table 'dba.[ '
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near 'dba.[ ' on line 1
1> drop table dba.[
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near '\' on line 1
1> drop table 'dba.[ '
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near 'dba.[ ' on line 1
1> drop table 'dba.[[ '
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near 'dba.[[ ' on line 1
1> drop table 'dba.['
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near 'dba.[' on line 1
1> drop table 'dba.[['
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near 'dba.[[' on line 1
1> drop table dba.[
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near '\' on line 1
1> drop table dba.'[ '
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near '[ ' on line 1
1> drop table dba.'[[ '
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near '[[ ' on line 1
1> drop table dba.'[[] '
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near '[[] ' on line 1
1> drop table dba.'[[] '
2> go
Msg 102, Level 15, State 0:
SQL Anywhere Error -131: Syntax error near '[[] ' on line 1
I'm fairly new to T-SQL, Stored Procedures and Microsoft SQL Server Management Studio.
I have created a View in my database called BodyBasics. In this View, there is a column called BackAngle. In the BackAngle column, I list at which angle the users back is bent. The datatype is float and can range from 90 to 180.
Some example values found in this View column are:
173,10786534157, 147,423570266, 170,196359990068, 148,774131860277, 153,439316876929, 147,063469480619, 173,861485242977, 172,1319088368, 145,416983331938, 163,02645970309, 147,65814822779, 146,212510299859, 173,769456580658
The View looks like this:
| ID | Timestamp | RecordingId | BodyNumber | BackAngle |
What I would like to do is SELECT the BackAngle data from the View in chronological order and plot the data into a graph.
The query I have tried is:
GO
DECLARE #BackAngle TABLE(Backangle FLOAT);
INSERT #BackAngle(Backangle) SELECT dbo.ViewBodies.BackAngle FROM dbo.ViewBodies
WHERE dbo.ViewBodies.BackAngle IS NOT NULL
ORDER BY Timestamp;
SELECT geometry::STGeomFromText( 'LINESTRING(' + #BackAngle(Backangle) + ')' );
GO
The errors that I get from this code is:
Msg 102, Level 15, State 1, Line 7
Incorrect syntax near 'Backangle'.
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '('.
I got the geometry::STGeomFromText syntax from this article:
http://sqlmag.com/t-sql/generating-charts-and-drawings-sql-server-management-studio
Can someone point out what is wrong with my code and whether this is the right way to do this? Is there any alternative?
You don't need a temp table you should make a TEXT STRING with variables to use it in LINESTRING. As a scale line you can use row numbers (1,2,3,4,...)
DECLARE #WKT AS VARCHAR(8000);
SET #WKT =
STUFF(
(SELECT ','
+ CAST( ROW_NUMBER()
OVER (ORDER BY [timestamp]) AS VARCHAR(100))
+ ' ' + CAST( BackAngle AS VARCHAR(30) )
FROM ViewBodies
WHERE BackAngle IS NOT NULL
ORDER BY [timestamp]
FOR XML PATH('')), 1, 1, '');
SELECT geometry::STGeomFromText( 'LINESTRING(' + #WKT + ')', 0 );
I have created new table in my database called T_AD_Data, when I am trying to join the table to V_ALL. getting error.
SELECT case V_ALL.JOB_qty_BlankPages when 0
then V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages + (V_ALL.JOB_qty_BlankPages + ((V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages * 2) - (V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages)))
else
V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages + V_ALL.JOB_qty_BlankPages
end as PrintedPages,V_ALL.JOB_qty_BWPages as BWPages,V_ALL.JOB_qty_ColorPages as ColorPages,
case V_ALL.JOB_qty_BlankPages when 0 then
V_ALL.JOB_qty_BlankPages + ((V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages * 2) - (V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages))
else V_ALL.JOB_qty_BlankPages
end as BlankPages,V_ALL.JOB_qty_SimplexPages as SimplexPages,
V_ALL.JOB_qty_DuplexPages * 2 as DuplexPages,
V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages as TotalSheets,V_All.JOB_lab_NTDomainName, V_All.Lab_GroupName, V_All.JOB_lab_NTUserName, V_All.Lab_NTFullUserName, V_All.PRINTER_lab_Location, V_All.JOB_lab_DocumentName, V_All.JOB_qty_Size, V_All.JOB_qty_Copies, V_All.JOB_date_Submitted, T_AD_Data.lab_sAMAccountName, T_AD_Data.lab_department, T_AD_Data.lab_physicalDeliveryOfficeName FROM V_ALL JOIN T_AD_Data AD_Data ON V_ALL.JOB_lab_NTUserName=T_AD_Data.lab_displayName;
Results:
Msg 4104, Level 16, State 1, Line 33
The multi-part identifier "T_AD_Data.lab_displayName" could not be bound.
Msg 4104, Level 16, State 1, Line 33
The multi-part identifier "T_AD_Data.lab_sAMAccountName" could not be bound.
Msg 4104, Level 16, State 1, Line 33
The multi-part identifier "T_AD_Data.lab_department" could not be bound.
Msg 4104, Level 16, State 1, Line 33
The multi-part identifier "T_AD_Data.lab_" could not be bound.
The Prefix T_AD_Data doesn't exist anywhere. You're attempting to use it in your join, but have no table named or aliased as such anywhere else in your FROM clause. Same goes for the last three fields of your SELECT.
It looks like either T_SBIL_AD_Data should be aliased as T_AD_Data (instead of SBIL_AD_Data), or you are you missing an entire table / view from your FROM clause.
EDIT: Using additional info from your comment, the answer is there is a table T_AD_Data that has columns you are referencing in both your SELECT and JOIN but the table is not anywhere in the FROM clause.
What you need is for your FROM clause to be something like this...
FROM
V_ALL
<SOME SORTA> JOIN T_AD_Data ON V_ALL.<Some_Field_In_V_All> = T_AD_Data.<Some_Field_In_T_AD_Data>
JOIN T_SBIL_AD_Data SBIL_AD_Data ON V_ALL.JOB_lab_NTUserName = T_AD_Data.lab_displayName
To be clear, <SOME SORTA> is a placeholder for whatever type of JOIN makes the most sense based on your actual data and the desired result (i.e. LEFT OUTER, INNER, etc.).
Also V_ALL.<Some_Field_In_V_All> and T_AD_Data.<Some_Field_In_T_AD_Data> are pseudocode placeholders for actual fields from each of those respective tables. Based on the field names you provided, maybe V_All.Lab_NTFullUserName and T_AD_Data.lab_sAMAccountName, but that's not much more than a guess.
I am trying to send emails individually to a list of recipients. I am receiving the error:
Msg 22050, Level 16, State 1, Line 0
Error formatting query, probably invalid parameters
Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 478
Query execution failed: Msg 4104, Level 16, State 1, Server xxxxxx, Line 1
The multi-part identifier "email#example.com" could not be bound.
Here is a simplified version of my code, asssuming table1 is a valid existing table and name and email are existing columns.
declare #current_mailaddress varchar(50), #query varchar(1000)
set #current_mailaddress = 'email#example.com'
set #query = 'select distinct name, email from table1
where email = ' + #current_email
exec msdb.dbo.sp_send_dbmail
#recipients = #current_email,
#subject = 'test',
#query = #query
So according to the error, the formatting (of presumably the #query) is wrong. I can't figure it out. Any ideas?
You need to put the value of #current_email in quotes:
'SELECT ... WHERE email = ''' + #current_email + ''''
To see why, consider what your query currently looks like without it:
SELECT ... WHERE email = email#example.com
Any time you work with dynamic SQL, it's a good idea to PRINT the variable for debugging if you get a strange error; it's usually the case that the SQL string you've built is not the one you're expecting. I suggested an easy way to manage debugging code in another, unrelated answer.