I am using MS SQL Server Version 2008 and MariaDB 10.5.
My table and data :
Following is the query i am running on both the databases.
select distinct distributor from market order by city
Found this query is failing in MS SQL Server database with error
SQL Error [145] [S0001]: ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
Understood the reason why it failing
Reason for - ORDER BY items must appear in the select list if SELECT DISTINCT is specified
when i ran the same query run with MariaDB it ran successful without any error and gave me below output.
So i have doubt why MariaDB is behave different here? ideally it should fail right?
Thanks in advance.
Please try this query
Select distinct col from (
Select col from table order by col
)
I have an Oracle Database, Which is linked to an Microsoft SQL Server, so I can query the server and spool information from the database without worries directly from SQL Server Management Studio. Now I want to pass a SQL query to fetch information from the linked server and display the values from the database.
So when I do this for instance
select * from openquery(LinkServerName,'select * from table_name')
This works 100%, no errors nothing.
Now when I run something like this
select * from openquery(LinkServerName,'select foracid,acct_name,acct_crncy_code,clr_bal_amt from table_name where bacid='1010000001' and sol_id='XXX'')
Where bacid and sol_id are both strings as columns, I get this return error:
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '1010000001'.
Please what do I appear to be missing?
select *
from openquery(LinkServerName,'select foracid,acct_name,acct_crncy_code,clr_bal_amt from table_name where bacid=''1010000001'' and sol_id=''XXX'' ')
should work, ' needs to be escaped by '' (two ').
Correction based on comment (escaping is somewhat strange in this case):
select *
from openquery(LinkServerName,'select
foracid,acct_name,acct_crncy_code,clr_bal_amt from table_name where
bacid=""1010000001"" and sol_id=""XXX"" ')
I have a Table HORAS_X with ID_HORA(int), ID_ZONA(int), DESCRIPCION(nvarchar), COMIDA(bit), META(int), NUMERO(int).
I can insert a single row like:
INSERT INTO HORA_X
(ID_HORA,ID_ZONA,DESCRIPCION,COMIDA,META,NUMERO)
VALUES
(2,2,'06:00-07:00',0,174,1);
And it works.
However when I try to insert multiple rows like this:
INSERT INTO HORA_X
(ID_HORA,ID_ZONA,DESCRIPCION,COMIDA,META,NUMERO)
VALUES
(3,3,'06:00-07:00',0,174,1),
(4,4,'06:00-07:00',0,174,1);
It throws the error
Msg 102, Level 15, State 1, Line 2 Wrong syntax near ','.`
Is my Syntax wrong? I checked online and it's supposed to be fine.
And yes, I have restarted SQL Server Manager, thanks for any lead and help.
If I remember correctly, SQL Server 2005 does not support VALUES table value constructor. It was introduced in SQL Server 2008, so for SQL Server 2005 you need to use the following statement:
INSERT INTO HORA_X (ID_HORA,ID_ZONA,DESCRIPCION,COMIDA,META,NUMERO) VALUES (3,3,'06:00-07:00',0,174,1)
INSERT INTO HORA_X (ID_HORA,ID_ZONA,DESCRIPCION,COMIDA,META,NUMERO) VALUES (4,4,'06:00-07:00',0,174,1);
Notes: SQL Server Manager Express 2005 is a tool, but I assume, that you are using SQL Server 2005.
I want to be able to create new tables based on any SQL select statement. I have tried the following which I got the format from another question and it does not work (there are similar questions but not one that I found actually works). I keep getting an error on the SQL statement.
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'AS'.
This is the CREATE TABLE statement:
CREATE TABLE MyNewTable
AS
SELECT *
FROM dbo.Bat
This will copy the entire table including rows
SELECT *
INTO newTableName
FROM dbo.Bat
Add WHERE 1 = 0 to copy just the table structure
If it is SQL Server (the dbo schema, default in SQL Server indicates it is SQL Server), you can do following.
select * into MyNewTable from dbo.Bat;
The SELECT INTO statement does not copy your table constraints.
You statement is a valid Oracle and MySQL statement though.
CREATE TABLE ... AS SELECT is simple (by deliberately ignoring for example the concepts of storage)
To create a table with all its lines
code:
CREATE TABLE XX AS SELECT * FROM YY ;
the result of command in mysql
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;