The set of rules that define the combinations of symbols that are considered to be correctly structured for that language.

learn more… | top users | synonyms

1
vote
2answers
390 views

Teradata view with “With Clause” syntax

I am trying to a view with "With" clause in Teradata but it is not allowing to create a view. Please suggest with any options. Given below is the query which I have tried: create view derived_table(...
12
votes
2answers
57k views

How do I declare and use variables in Oracle?

My main skills are with SQL Server, but I have been asked to do some tuning of an Oracle query. I have written the following SQL: declare @startDate int select @startDate = 20110501 And I get this ...
2
votes
2answers
58 views

PL/pgSQL regclass quoting of table named like keyword

I want to create a new table name based on an existing one by appending a suffix to it. A Postgres 9.5 PL/pgSQL function gets the existing table name passed in as regclass type and returns the new ...
2
votes
0answers
50 views

SSDT Syntax Error 80001 on every Select statement starting with “(”

Visual Studio / SSDT marks the following script line as wrong giving "SQL80001 Wrong Syntax next to SELECT" and also "SQL80001 Wrong syntax next to ')'" error. (select a from [tab1]) union (Select a ...
1
vote
1answer
27 views

Postgresql perl : “NOTICE: elseif should be elsif at line …”

It's not the first time I get this strange NOTICE when adding perl functions in Postgresql : NOTICE: elseif should be elsif at line 11. This happens at CREATE FUNCTION as well as when using the ...
0
votes
2answers
168 views

using update query with subquery in Oracle sql

I have an update query where I am trying to update a field but for more than one record, I am trying a join but it doesn't work. Below I get multiple values that come back from the select statement ...
17
votes
3answers
45k views

MySQL Set UTC time as default timestamp

How do I set a timestamp column whose default value is the current UTC time? MySQL uses UTC_TIMESTAMP() function for UTC timestamp: mysql> SELECT UTC_TIMESTAMP(); +---------------------+ | ...
11
votes
4answers
6k views

Why do we use Group by 1 and Group by 1,2,3 in SQL query?

In SQL queries, we do use Group by clause to apply aggregate functions. But what is the purpose behind using numeric value instead of column name with Group by clause? For example: Group by 1.
0
votes
1answer
212 views

How to only display a variable in PHP inside a MySQL query when it has a content or when a condition is true?

How do I only display $mon or any variable when it has content? whenever i use this syntax and for example, monday must contain the number 1 and tuesday would contain number 2 and the other ones have ...
1
vote
1answer
58 views

Syntax Error Help [closed]

I have this script that works just fine but when I change the directory paths it seems to get this syntax error "unclosed quotation mark after the character string" I have looked over this for hours ...
0
votes
1answer
41 views

Syntax help in SQLPLUS

Does Oracle have any builtin SQL syntax help. I find I may have forgotten a few statements and sometimes have no Internet access. I am using Oracle 11g.
1
vote
1answer
62 views

Is the SQL syntax for InnoDB gauranteed to be the same between MySQL, MariaDB and Percona?

I develop an application that uses MySQL and explicitly uses InnoDB table engine. In a few cases we have clients using this application with MariaDB or Percona. I understand that MariaDB and Percona ...
0
votes
1answer
68 views

Alter table add column like another column syntax

I was looking into MySQL specification, but couldn't find any solution to my problem. I want to clone specific columns in several tables like this: ALTER TABLE `table` ADD COLUMN `new_column` LIKE `...
0
votes
1answer
40 views

Syntax Error CREATE TABLE Statement [closed]

i am getting a Syntax error in CREATE TABLE statement. Microsoft Access 2007. CREATE TABLE ROOMS ( RoomNum Int Not Null, RoomSize Char(6) Not Null, RoomBedCnt Int Not Null, RoomRate Numeric(18,2) ...
3
votes
1answer
61 views

ORDER BY count and Bitmap Heap Scan

I have a table with hits: Column | Type | Modifiers --------------+-----------------------------+--------------------------------...
3
votes
1answer
49 views

Timestamp Difference - Syntax Error - Condtitional Selects

Here is what I have right now SELECT name, admin, reason, unban, FROM_UNIXTIME(date) AS datetime, HOUR(difference) AS HRemain, MINUTE(difference) AS MRemain FROM (SEC_TO_TIME(AVG(TIMESTAMPDIFF(MINUTE,...
1
vote
1answer
60 views

Postgresql uuid syntax error

I am trying to insert/update a foreign key field which is also a uuid to use the correct fk id for this set of data: zuri=# ALTER TABLE newarts ALTER COLUMN jurisdiction_id SET DEFAULT a82857b6-e336-...
2
votes
1answer
63 views

What is the purpose of the Save Transaction statement?

I read up on SAVE TRANSACTION, but I'm not completely sure I understand it. I'm aware of the concept of transactions as far as BEGIN, COMMIT, and ROLLBACK, but this is a new one. It sounds almost ...
0
votes
0answers
46 views

MySQL/MariaDB: Can I drop KEY declatations in sql dump for CREATE TABLE for foreign keys?

I prepare Liquibase schema creation changelog for legacy DB. I started with SQL dump and refined it by little sed processing so I have only CREATE TABLE statements. It looks like: CREATE TABLE `...
2
votes
1answer
520 views

what is '#' in create table statement?

I recently saw a statement like: CREATE TABLE #tbl_AR_Data I wanted to know what is the purpose of the symbol # (NUMBER SIGN, hash, pound sign) in this statement?
31
votes
4answers
11k views

Performance difference for COALESCE versus ISNULL?

I've seen a lot of people use the COALESCE function in place of ISNULL. From internet searches, I've found that COALESCE is ANSI standard, so there is an advantage that we know what to expect when ...
0
votes
1answer
263 views

Syntax error with concat in trigger near signal statement

Please help me with syntax for MySQL 5.6. For some reason I get the error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version ...
0
votes
1answer
434 views

SQL80001 - incorrect syntax near ')'

In the below code (that I've inherited), I'm getting the message "SQL80001 - incorrect syntax near ')'", the error being on the third line from the bottom with the + sign. I've looked at THIS SO ...
0
votes
1answer
50 views

How to select the first unique data type in a table

Sorry for the messy layout question. This is my first post. I have the following table structure under ORACLE database List item Row A B Date 1 X X 01-2012 2 ...
0
votes
1answer
226 views

Teradata sql syntax from date to quarter

Need a Teradata sql syntax to extract quarter from a date. Given below is the expected output Date: (YYYY-MM-DD) 2015-09-12 2015-05-22 2014-12-15 Output 3Q15 2Q15 4Q14 Query which I have ...
1
vote
1answer
80 views

SSIS Derived Column Conditional Time Modification

I'm using SSIS to transfer data from a MySQL database to a SQL Server one. There's one point that I'm currently stuck on, however. MySQL TIME datatype supports values greater than or equal to 24:00:00,...
9
votes
2answers
42k views

What is the easiest way to move data from Oracle to SQL Server?

One of our products supports both Oracle and SQL Server as database backend. We have a customer who wishes to switch from an Oracle backend to Microsoft SQL Server, which isn't a typical transition ...
0
votes
0answers
10 views

Reason of poor performance of ANSI joins in Oracle 9i

Please before flagging as duplicate, read the last paragraphs. In an Oracle 9i database this query runs in 0.18 seconds: select count(*) from dba_synonyms s,dba_objects t where s....
2
votes
1answer
167 views

Converting old SQL Server outer join syntax

I'm a Power Builder (PB) developer. I've migrated PB from 10 .5 to 12.5, and now I need to migrate the stored procedures from SQL Server 2005 to 2012 as well. I get a invalid expression error when I ...
1
vote
2answers
323 views

Use array expression from subquery in ANY() condition

I have a relatively complicated query with a subquery fetching an array like so: ... ARRAY(SELECT category_id FROM category_schedule_con con WHERE s.id = con.schedule_id ORDER BY category_id) ...
2
votes
1answer
103 views

What column is this alias referring to?

I've read the following code a few times trying to figure out what it is doing. "A right outer join is that which returns the unmatched rows from the right tables with matched rows from the left ...
1
vote
2answers
120 views

Weird Syntax Error [closed]

I'm working with MySQL 5.6 on a Ubuntu 14.04 server. Checking in this online syntax checker: https://sql.treasuredata.com/ The syntax checker tool throws the exception: mismatched input 'NOT' ...
0
votes
3answers
4k views

I'm trying to use a variable in Oracle PL/SQL, but I'm getting an error. What's wrong here?

I come from an SQL Server background and I'm trying to figure out how to use Oracle PL/SQL variables. I'm trying to declare a variable and then select that variable. It sounds simple, but I am doing ...
0
votes
1answer
103 views

How can we drop a constraint without losing the automatically created index?

How can we drop a constraint without losing the automatically created index? If it's possible using a single query.
1
vote
1answer
97 views

select members with the longest running absence streak

I have a database containing a table that stores attendance data, and its columns are member_id and datetime_attended. And another table storing members info, which is made up by the columns id and ...
2
votes
1answer
506 views

Arithmetic overflow error varchar to numeric

I'm getting an arithmetic overflow error and I can't seem to find out the case. I've recently had to adjust some stored procedures, to allow for dates in the future to be put in. The following part ...
2
votes
2answers
106 views

Can't select 2 tables at the same time

I have a pesId (peopleId) column at pessoas (people) where is stored data from medics and patient. Also I have a table that stores medical consult information like Date, patient id, medic id and ...
3
votes
2answers
543 views

Why is it truncate table, and not simply truncate?

Upon reviewing some of our code a colleague posited that he was annoyed at always having to write TRUNCATE TABLE when there is no real other usage for TRUNCATE. Googling this, I indeed can not find a ...
3
votes
3answers
174 views

SQL SSIS syntax question

What do you call the following expression? (TableName == NULL) ? "0" : TableName I have a sense of what it does, but would like to look up the whole syntax definition, however as there is no real ...
0
votes
1answer
457 views

“Incorrect Syntax near S” in Stored Procedure [closed]

I'm creating a SQL Server stored procedure and getting error Incorrect Syntax near S I'm not able to find the exact reason of the error. CREATE PROCEDURE RPT_IVR_CALL_SUMMARY (@...
2
votes
2answers
265 views

Upgrading a database from SQL Server 2005 to 2012 uncovered a syntax error

I recently upgraded from SQL Server 2005 to 2012. During validation however, a bug was discovered. A certain trigger was coded as follows: CREATE TRIGGER [dbo].[trigger] on [dbo].[foo] FOR UPDATE, ...
0
votes
1answer
73 views

Help converting a MySQL query to postgres

Is it possible to do this query in postgresql? SET @p:= 0; UPDATE t SET x=CEIL((@p:= @p + 1) / $n) ORDER BY id DESC; I'm struggling with the variable syntax. I tried: \set p 0 update t set x=CEIL(...
0
votes
2answers
82 views

How can I move backups location?

I have a seemingly easy question. How can I move a xxx.bak file to another location with T-sql? I have a job that takes a copy from database a to c:mycopy/copy1/a.bak and I want to create a step that ...
0
votes
1answer
4k views

Oracle: how to set only some roles as not default for a user (no GUI)

Scenario: I have instanceA I have instanceB I have USER1 in instanceA I have USER1 in instanceB USER1 in instancA has four roles grante to it: ROLE1 default yes admin_option no ROLE2 default false ...
0
votes
1answer
146 views

Syntax Error In Postgresql Function [closed]

Why am I getting: ERROR: syntax error at or near "'SELECT '" In: CREATE OR REPLACE FUNCTION GetListings (lon double precision, lat double precision, schemas name[]) RETURNS TABLE( schema ...
8
votes
2answers
13k views

How to create a temporary table using VALUES in PostgreSQL

I am learning PostgreSQL and trying to figure out how to create a temporary table or a WITH declaration that can be used in place of regular table, for debugging purposes. I looked at the ...
2
votes
2answers
935 views

Lines starting with colons in SQL Server

Playing around with DB projects, Visual Studio generated a change script with the following lines: GO SET ANSI_NULLS, ANSI_PADDING --etc.; SET NUMERIC_ROUNDABORT OFF; GO :setvar DatabaseName "Foo" :...
2
votes
1answer
5k views

How to join a table with a table valued function?

I have a user defined function: create function ut_FooFunc(@fooID bigint, @anotherParam tinyint) returns @tbl Table (Field1 int, Field2 varchar(100)) as begin -- blah blah end Now I want to join ...
-1
votes
1answer
85 views

what is the syntax for insert trigger?

I am very new to sql. feel a little stupid to ask this question Say I have this table Warehouse(shipperid, name , state). Then I define another table warehouse_maine (shipperid, name, state) which ...