Tagged Questions

An acronym for "Structured Query Language" (it's not the name of a specific DBMS product), SQL can be used in relational database management systems (RDBMS) to query, update, delete, and insert data as well as modify the structure of the database. It can also be used to manage schemas and data ...

learn more… | top users | synonyms (1)

0
votes
0answers
19 views

Where statement involving isnull/case

Here is my query: [SuggestedRetailPrice] > 0 AND (ISNULL( CASE WHEN [AdEnd] < GETDATE() THEN [AdPrice] END, [BasePrice]) )/[SuggestedRetailPrice] > 0.8 ...
0
votes
1answer
26 views

Sum(Case When) Question

I'm trying to get the syntax correct on my query but I'm having issues. Currently my query will show the Household Total Value (HHValue) and then the NationalValue on one row, then the second row ...
0
votes
1answer
18 views

Populate a table with “WITH” clause

How to perform the following select query? with x (x, y, z) as ((2 5 6), (6,3,2)) select * from x I am not sure if this approach is possible. Not even sure if the syntax is correct. But I don't ...
0
votes
0answers
4 views

HSQLDB 1.8: Trying to have the result table contain two records in each row and be sorted

I'm really stuck doing this because each time I think I have a solution, HSQLDB v1.8 doesn't support it. I am forced to use this version at work, and believe me, I wish I could use a new DB, even v2.x ...
1
vote
1answer
39 views

SQL Pivot column

I'm trying to figure out how to create a From and To column based on ID.LocationID Column. I'm hoping with a suggestion this can be done (i can figure it out) without having to create sample tables ...
2
votes
1answer
60 views

Why am I getting cardinality issues when querying a single table

I have the following query: SELECT [iri].[RateItemKey], [iri].[RateItemType] FROM [prism72].[dbo].[ispRateItem] AS [iri] WHERE [iri].[Status] = 1 AND ( ...
3
votes
2answers
67 views

CTE works as expected, but not when wrapped into a function

--testing table CREATE TABLE public.test_patient_table ( entity_id INTEGER NOT NULL, site_held_at INTEGER NOT NULL, CONSTRAINT entityid_pk PRIMARY KEY ...
3
votes
3answers
437 views

How to achieve many to many relationship in this database design?

I am currently working on small travel application in which users can add other users' trips in their wishlist. I am facing difficulty in designing database for wishlist. What I have tried so far is: ...
-1
votes
2answers
38 views

Calculate number of items with distinction using SQL [on hold]

I have a product Table like this; Product | Operation | Component A | 10 | C1 A | 10 | C2 A | 11 | C3 B | 12 | C3 B | 11 | C1 B ...
0
votes
0answers
11 views

How to import to UNIX the results from a select query?

After a select query i get around 14k records.Rather than exporting them as insert statements into a file and then executing from UNIX, i want to import them to UNIX directly and insert so as to save ...
0
votes
1answer
37 views

Work with table named Group [on hold]

I have a table named Group in my database , when I try to work on it it gave error : SELECT GroupID,GroupName FROM Group it said : Msg 102, Level 15, State 1, Line 1 Incorrect syntax ...
1
vote
1answer
22 views

Correlated query Issue [on hold]

In the below query i have 2 tables product and productstatus. In product table I have productId and productName and in productstatus table there are locationid,productid,currentstock and ...
1
vote
2answers
34 views

Is a Postgres long-running query aborted if the connection is lost/broken?

If I open a connection to Postgres and issue a long-running query, and then break the connection (e.g., kill the client process that opened the connection), will the long-running query continue to ...
0
votes
1answer
52 views

Why is Excel File Opened Exclusively By Another?

I'm creating an SSIS package to loop through a series of Excel files (.xls). I create my while loop container and then create my data flow, which includes an Excel source. When I edit my Excel ...
-3
votes
1answer
35 views

Char in select why [on hold]

In sqlplus query eg: select a.phonumber from customers a where User = 'mark' Why using the character a -- what is benefit? Thanks
1
vote
2answers
92 views

Currently all connections getting “Timeout expired”

I have an application which connects to SQL Server. Currently I am getting, Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because ...
2
votes
3answers
171 views

SELECT all substrings (n-grams) of length n?

How could I select all n-grams, ie. substrings of length n from a string using SQL? For example, the 3-grams of string example are exa, xam, amp, mpl, ple. I'm using PostgreSQL to be more precise.
1
vote
1answer
53 views

WITH RECOMPILE option in SQL Server [on hold]

When you have multiple connections concurrently trying to execute the query by using different parameters in the filter condition with recompile option, Is there are any chance that it may produce ...
2
votes
2answers
43 views

Postgresql and UTF8 to Latin1 conversion?

We have a Postgresql database where the data is in Latin1. Apparently someone loaded some UTF8 encoded data into it since when I select data from some of the columns, I get stuff like: SELECT ...
0
votes
1answer
39 views

SQL Query - How do I Select Into new columns

I'm trying to write a query that will put values in three different columns. I have the query pulling the information I need, I just don't know how to split the values out into different columns. ...
-3
votes
0answers
20 views

Database information [on hold]

Where should I put all the database? Where do you put it as a reference? I am not doing this I haven't begin but, I need to know where does it go I can't save it in a desktop that's why.
0
votes
1answer
20 views

Achievement Table [on hold]

I have a table with the offers and I need to relate this table to some requiremnts to get such an offer. For example let's say the offer say 50% of discount on the ticket if you buy 3 cokes and come ...
-1
votes
0answers
26 views

Compare data from two columns for different dates in Sql [on hold]

I have a table containing dates, names and marks. I just wanted to write a query to retrieve different of marks between t-1 and t-2 dates for same names that's query should give me big movers everyday ...
1
vote
2answers
43 views

Insert New Foreign Key Row for new Strings

Lets say I have a table new_data like this: ndx | someval | somemachine serial | integer | integer ---------------------------- And let's say I have a reference table new_data_someval_ref: ...
1
vote
1answer
32 views

Database design: 4 types of users but have different functionality , separate or one table?

I have 4 types of users: Admins , normal user , company , service provider admins and normal user share some attributes (id .first name ,last name ,phone ,mail) company and service provider share ...
0
votes
1answer
41 views

Select Statement to generate result, for Group by per second and link with Table

i tried to search in existing queries but didnt find any related thread. i would like to run a query in user table (for example), and like to get output result on per second bases. and give me zero ...
-2
votes
1answer
45 views

Retrieving data from multiple table with filter criteria [on hold]

I have a table with the following data: A B C --------- --------- --------- 40 1111 Null 40 1123 Null 40 1023 abc 66 1456 Null 66 ...
0
votes
1answer
43 views

SQL Server stored procedure that would enforce atomicity?

Let's say I have following insert statements INSERT INTO tEmpl (lastName) VALUES('Smith') INSERT INTO tEmpl (lastName) VALUES('Jones') INSERT INTO tEmpl (lastName) VALUES('Smitty') INSERT INTO ...
0
votes
1answer
30 views

How to make get a Row Change from SQL [on hold]

I've a question related to SQL Query with sample data tblModel(MODEL nvarchar(50)) MODEL MODELA MODELB MODELB MODELC MODELA MODELA MODELA MODELC I want to make a query to show data with ...
-2
votes
1answer
57 views

Why is this SQL query illegal? [on hold]

Students is a table with two fields name and grade for a number of students. I wonder why the following query in SQL is said to be illegal: SELECT Students.name, MAX(Students.grade) FROM Students; ...
0
votes
0answers
13 views

SQL: Dynamic Pivot Column, In the column's row value How to get Top 1 value

In my following query I need to get the top 1st record's value in pivot row value. So basically I get all parts and if there is a service entry with that part and a revision number I used that ...
0
votes
1answer
15 views

Postgres Grouping of Like Results

Our database is running on Postgres 9.3. We have a table called notifications. Notifications contains id, type, triggering id, source id, and some other information. What I am trying to do is select ...
1
vote
1answer
58 views

SSRS pivot dynamic columns

I've tried to port this from a similar post, SQL query to return a column per date in date range? however I haven't been able to quite get it to do what I need... Please find some example code below : ...
1
vote
1answer
52 views

Delete from table where two of the three keys in another select

I have tableA which has 4 columns: IDA (bigint), IDB (int), IDC (varchar(255)) and comment (varchar(255)). The primary key is (IDA, IDB, IDC). I'm required to delete the records where the count of ...
0
votes
1answer
24 views

Transform it into 3NF [on hold]

Consider the relation LEASE, where a person can live in only one building, and a building can charge only one rental rate: RELATION = LEASE (PersonID, BuildingID, Rent), Primary Key = {PersonID} I ...
0
votes
2answers
60 views

SQL - Cannot Add Foreign Key Constraint

Can anyone tell me why there are errors such as : Cannot Add Foreign Key Constraint And am i on the right track ? DROP DATABASE technology_university_hospital; CREATE DATABASE ...
0
votes
1answer
28 views

Most used tables in MySQL database server

Can somebody please help me with a query that lists the most used tables in a MySQL database? Or how can i find out the most used tables in the database? Thanks
1
vote
0answers
65 views

MDF/TempDB Growth, SQL Server 2005 Enterprise

Here's my scenario: SQL Server 2005 Enterprise Records from Database A being added to Database B Size of Database A MDF file: 3.15 GB I have separate drives for Data, Logs, and System. I ran a ...
2
votes
4answers
177 views

Re-writing a sub-select as a condition on a column generated with 'over (partition by …)'

I am wondering if it would be possible to use over (partition by...) clause in order to avoid using a sub-select in the example below: declare @t table ( id int ,code char(2) ...
0
votes
3answers
24 views

Case when not return more than one value

I try this, but the SwitchCase can not return more than one value. WHERE CP.NumIntAut IN ( CASE WHEN @NumIntAut IS NOT NULL THEN (@NumIntAut) ELSE (SELECT NumIntAut FROM ...
1
vote
3answers
34 views

Get seconds of day in Postgres

In Java we use Joda-Time to get the seconds of a day as an int value (despite the date): date: 10-10-2014 00:00:30 -> second 30 of day date: 11-10-2014 00:01:30 -> second 90 of day date: ...
0
votes
1answer
13 views

Replication Snapshot folder not cleaning up

The job that I thought was supposed to clean up old snapshots isn't removing the old files. The retention is left at default yet there are snapshots months old which remain. The job runs as the ...
1
vote
1answer
50 views

Set bit in Table A if values are present in Table B

I have two tables, Containing up to ~10 million entries. TableA which has 3 columns: IDA (bigint), IDB (int) and CHK (bit). (IDA, IDB) is the primary key. TableB which has 2 columns: IDA (bigint), ...
0
votes
1answer
12 views

Machine account causing a Token-based server access validation failed with an infrastructure error

As the error suggests the SQL log is filling with the error: Login failed for user 'xxx\xxx$'. Reason: Token-based server access validation failed with an infrastructure error. Check for previous ...
1
vote
1answer
33 views

Slow Query with LIMIT

We have this query: SELECT "messages".* FROM "messages" WHERE "messages"."account_id" = 1 AND "messages"."status" = 'unread' AND (created_at >= '2014-04-24 01:00:00.000000') ORDER BY id DESC It ...
0
votes
0answers
31 views

One to many size and performance

Is it worth to create a inverted relationship in order to have faster searches? My entity has 10 possible values on the Many side of the mapping, most of the time the 10 will be selected. Let's call ...
1
vote
1answer
20 views

How to group by on two fields and count

CREATE TABLE IF NOT EXISTS `usuarios` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user1` varchar(255) DEFAULT NULL, `user2` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT ...
1
vote
1answer
70 views

Query performance issues

I need help in improving the performance of the following query. It has the purpose to select one record out of a group of records with an identical ID (doublettes). Rules are that Date2 must be the ...
0
votes
0answers
11 views

first query on my table takes apx: 0 sec but taking too much time on or after 3 to 4 query

I have the following table in mysql database: CREATE TABLE `chronologicallists` ( `sno` int(250) NOT NULL AUTO_INCREMENT, `empSno` int(11) NOT NULL COMMENT 'Employee Serial Number', ...
0
votes
1answer
22 views

update column without auto timestamp update

Hello everyone I have got a product stock table with a time-stamp column so the so any updated to that row will update the time stamp ,I'm happy with this setting but sometimes I want to update the ...