Why does SQL Server report that this statement isn't correct?
use DIGITECH
go
select *
from kunde as k
left join adresse as a on k.FK_AdID = a.AdID
where Name = 'Dirk'
go
SQL displays this error (in German):
Meldung 102, Ebene 15, Status 1, Zeile 14
Falsche Syntax in der Nähe von 'go'.
Meldung 102, Ebene 15, Status 1, Zeile 14
Falsche Syntax in der Nähe von 'go'.
Translated to english:
Msg 102 , Level 15 , State 1, Line 14
Incorrect syntax near 'go' .
Msg 102 , Level 15 , State 1, Line 14
Incorrect syntax near 'go' .
As other have pointed out, GO is the default batch delimiter for tools like Management Studio or sqlcmd. SQL Server does not understand GO, the tools use it to separate batches and send individual batches to SQL Server. You probably took an entire .sql file and executed in your app.
You can use a library like DbUtilSqlCmd which understands the sqlcmd delimiters (GO), and other sqlcmd specific syntax like :setvar, and execute your .sql file through it.
Can you specify the database in the query and avoid the go statements? For example:
select * from DIGITECH.dbo.kunde as k
left join DIGITECH.dbo.adresse as a
on k.FK_AdID = a.AdID
where Name = 'Dirk'
Related
Hi i am getting this error Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '' and i dont know from where is the problem. That is the code and also i attached a screenshot.
USE CobornSalesDB;
GO
INSERT INTO SalesActivity
VALUES ('AC00001','05-12-2016','AG16170','C000001',
'P0001','S00002',1,200000.00,NULL,1.2220,20,100000.00,
'12-25-2016','12-30-2016','12-31-2016','A000001','PR00001');
GO
![SCREENSHOT][1]
You have a hidden character
If I convert to ANSI in NotePad++
INSERT INTO
SalesActivity
VALUES
(
'AC00001',
'05-12-2016',
'AG16170',
'C000001',
'P0001',
'S00002'‌​, --this bad boy
1 ,
200000.00,
NULL,
1.2220,
20 ,
100000.00,
'12-25-2016',
'12-30-2016',
'12-31-2016',
'A000001',
'PR00001');
GO
I want to return the character 'o' in my sql database while working with xml data so I wrote the following query:
use master
select song_type.query ('table/[where o.name like % o %]')
from xmldata
but the program returned an error saying:
Msg 9341, Level 16, State 1, Line 2
XQuery [xmldata.song_type.query()]: Syntax error near '[', expected a step expression.
please how do I fix this.
Try this ...
select *
from xmldata where cast(convert(varchar(max),song_type) as xml).value("o.name[0]","varchar(500)") like '% o %'
I want to create a dynamic update query where I need to set a certain value in a column. But the column name needs to be SELECTed from another table.
I have already the following query:
UPDATE core.TableRes
SET (
SELECT Code FROM core.TableFields
INNER JOIN core.TableXTableFields ON TableXTableFields.FieldID = TableFields.FieldID
INNER JOIN core.TableResRefLinks ON TableResRefLinks.ExtraFieldID = TableXTableFields.ExtraFieldID
WHERE TableResRefLinks.TableResRefLinksID = RefLinks.TableResRefLinksID)
= (
SELECT Value FROM core.TableResRefLinks WHERE TableResRefLinksID = RefLinks.TableResRefLinksID)
FROM core.TableRes
INNER JOIN core.TableResRefLinks RefLinks ON RefLinks.ResourceID = TableRes.ResourceID
INNER JOIN core.TableXTableFields ON TableXTableFields.ExtraFieldID = RefLinks.ExtraFieldID
INNER JOIN core.TableFields ON TableFields.FieldID = TableXTableFields.FieldID
WHERE (EndDate IS NULL OR EndDate > GETDATE()) AND
(
SELECT Code FROM core.TableFields
INNER JOIN core.TableXTableFields ON TableXTableFields.FieldID = TableFields.FieldID
INNER JOIN core.TableResRefLinks ON TableResRefLinks.ExtraFieldID = TableXTableFields.ExtraFieldID
WHERE TableResRefLinks.TableResRefLinksID = RefLinks.TableResRefLinksID)
<>
(
SELECT Value FROM core.TableResRefLinks
WHERE TableResRefLinksID = RefLinks.TableResRefLinksID)
It gives me the following errors:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'FROM'.
Msg 102, Level 15, State 1, Line 14
Incorrect syntax near '<'.
Is there a way to solve this? If I change the complete UPDATE and SET statements and replace them with a SELECT *, I get results.
EDIT
Here are the datatypes
TableFields.Code => nvarchar(100)
TableResRefLinks.Value => sql_variant
And the datatypes of the columns that have as column name TableFields.Code are set as sql_variant
You can't solve this using plain SQL. You would need some kind of scripting to build your statement. For example postgresql has a scripting language called "pgpsql" which allows building dynamic SQL statements. But this clearly depends on the underlying RDBMS.
By the way: this works with SELECT as you are doing simple sub-select.
I have the typical table:
LSRNbr BatchNbr
111 1212
111 1414
And the query should return:
LSRNbr BatchNbr
111 1212, 1414
I was browsing for a solution to this and I found these two:
Solution 1:
;WITH C AS
(
SELECT LSRNbr, BatchNbr FROM tblDTS_LSRBatch
)
SELECT Distinct LSRNbr,
STUFF((SELECT ';' + BatchNbr FROM tblDTS_LSRBatch WHERE LSRNbr = c.LSRNbr FOR XML PATH('')),1,1,'')
FROM C
error:
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ';'.
Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near 'XML'.
Solution 2:
SELECT
[LSRNbr], REPLACE(RTRIM((SELECT [BatchNbr] + ' ' FROM tblDTS_LSRBatch WHERE (LSRNbr = Results.LSRNbr ) FOR XML PATH (''))),' ',', ') AS NameValues
FROM tblDTS_LSRBatch Results
GROUP BY LSRNbr
error:
Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'XML'.
But none of them worked for me, see errors above please.
What could be the problem here?
I'm using Microsoft SQL Server 2005
These are syntax errors.
You'll learn more from figuring out the particular error yourself:
Take a look at the syntax tree
Take a look at some good examples of what you're trying to do
If you still have trouble, feel free to ask more questions
i am facing error wile running this in sql server 2000
bcp "select dmedocno ,dmename,dmeauthor,dmekeywords from document
where repositoryid=4 and dmedocno between 1 and 60000 order by
dmedocno" queryout c:\LR_Query29_cutover_19_August.csv -Swsapp0772 -T -c -t","
Error is:
Server: Msg 103, Level 15, State 7, Line 1
The identifier that starts with 'select dmedocno ,dmename,dmeauthor,dmekeywords from document where repositoryid=4 and dmedocno between 1 and 60000 order by dmed' is too long. Maximum length is 128.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'queryout'.
why your sql server treats the query as identifier? hm...
Check default QUOTED_IDENTIFIER option for the server, try to set it to OFF