Structured Query Language (SQL). For questions about the language, not Microsoft SQL Server (tag sql-server).

learn more… | top users | synonyms (2)

1
vote
1answer
11 views

Joining Tables in the FROM vs. the WHERE clause

First time caller here. I have a question regarding best practices when joining tables. For example, both of the following queries return the same results: SELECT i.id, p.first_name, p.last_name ...
-1
votes
1answer
14 views

How can I create a church attendance report system?

Please am pretty new to php and mysql. I have an assignment to create a church attendance system for our weekly services. The system would be able to know how many males and females came to church ...
3
votes
1answer
11 views

Can SSDT deploy SQL server service broker objects?

Can SQL Server Data Tools (SSDT) deploy sql server broker objects? (So contacts, message types, services, queues and so on.)
0
votes
1answer
10 views

Modeling Optional Column

I've got an optional column (residential) in one of my tables that is giving me trouble. If a Licensee intends to work w/ residential customers, they need to take an additional course (...
0
votes
1answer
22 views

Database consists of a lot of unused columns and every table has same schema

I am a web developer so I don't know a lot about databases. The company I joined recently has a very mature Desktop ERP built in .NET and SQL Server, they are providing services to huge corporate ...
0
votes
0answers
5 views

postgres create a view with data transformation rules

I was hoping someone could point me to a resource that can help me solve my problem. I have a largish dataset (25 Million rows), and I need to export the table based on a set of rules. 6 rules to ...
0
votes
1answer
23 views

Updating and/or inserting several rows in the same SQL statement

I am implementing an account "ability" type thing - a users account is given the abilty to do one or many things in the system, like (simple examples) cancel orders or pay invoices. I have a table ...
1
vote
2answers
165 views

Get first and last record for each date and calculate their difference

I need to calculate the DATEDIFF in seconds between the First record for each date with EventCode = 1 and the last record for each date with EventCode = 2. I have posted a sample data set for 2 days ...
0
votes
0answers
21 views

Finding records only when all ids present in a group

Having these two tables id | val TableA -------- 1 | A 2 | B 3 | A 4 | B 5 | A 6 | C 7 | D id_A | data TableB ----------- 1 | a 2 | b 3 | c 5 | d 7 | e First I ...
0
votes
0answers
14 views

why execution time change between each run

I have a pgAgent job connecting to a remote server: Every minute bring ~400 records. Job take ~500 ms Result are save in avl_pool (avl_id, x, y, azimuth, near_link) last one is null here I ...
0
votes
0answers
13 views

Design: Available domain database

I'm building website and service that will allow user to check if given domain is available. Right now I'm thinking about good way to store result from whois, but i dont want to store whole response ...
0
votes
0answers
30 views

SQL Retrieval Into Excel HELP! [on hold]

The picture shows the format of E1 to maybe help out visually. I'm an intern and I work for an engineering company. As a project, I want to streamline the document control [DC] process and save time. ...
0
votes
3answers
29 views

Page life expectancy very low on certain time?

Everyday we receive an alert on a specific period (03:00 AM - 04:00 AM) indicating that Page life expectancy is too low : SCOM :Alert: SQL DB 2008 Engine Page Life Expectancy is too low We have ...
0
votes
0answers
37 views

SSIS all executions report query

At first - hello DB specialists! I'm trying to prepare a query, which in result give me a specific information about SSIS jobs and errors if occurs. I found some hints on google and finally I have a ...
0
votes
1answer
24 views

How to store data having a fixed number of columns and a variable number of rows

I have posted this question in the stack overflow site and a more experienced user than me suggested I post it here. I am quite new at collecting data and am collecting a new dataset using R from ...
0
votes
0answers
21 views

mysql select duplicate columns for same row

Ok I'm trying to write a customized report for a preexsiting database(IE, I didn't design it and can't change the convoluted structure) that has a user table and 2 other tables that store user ...
1
vote
0answers
16 views

Join Tables of Varying Criteria in Order of Priority

I am trying to join two tables based on varying criteria in order of priority. The situation I have inherited a clinical database which has inherently bad data quality from years of poor input and ...
1
vote
1answer
52 views

SQL parsing XML

I'm receiving XML files as part of an EDI setup and I'm having an issues getting information from the child elements. Here is the XML file: <?xml version="1.0" encoding="UTF-8"?> <cpi_event&...
0
votes
1answer
21 views

How to connect to an Oracle db using a stored procedures within a Microsoft SQL server? [on hold]

I need to verify data between and Oracle db and a Microsoft SQL server db to verify that if there differences between the two and then update the Microsoft SQL server with any changes there may be
0
votes
1answer
25 views

Join query result of 2 different tables based on common column

I want to join the result of two different queries from two different tables based on a common column (which is named differently in the two tables) but I cant seem to figure out the easy way to do it....
2
votes
1answer
55 views

Calculating a percentage discount in SQL [on hold]

Basically just started using sql and having a minor problem. Working out the percentage of a number. Example: What would I need to type in to work out: 2.75 - 5% Drink_price= 2.75 After 5%...
0
votes
1answer
29 views

SSIS: Import Excel file to SQL Server

Is there a Excel version for this article? I have been searching for this past days but there is no luck. https://www.simple-talk.com/sql/ssis/ssis-basics-introducing-the-foreach-loop-container/
2
votes
2answers
55 views

UNION ALL w/ MINUS

Why does: select 1 FROM DUAL UNION ALL select 1 FROM DUAL MINUS SELECT 2 FROM DUAL return only a single 1 rather than 2 rows of 1 in Oracle?
0
votes
0answers
5 views

How to group and number query results with a resetting counter

I apologize for the quality of the title and the following description since I'm having a hard time explaining (and searching for) what I need. I have a query that returns a list of customers and ...
0
votes
0answers
17 views

Querying Table from another Database using Synonyms

I have two databases(A,B). on database "A" i created synonyms CREATE SYNONYM [dbo].[Names] FOR [server1].[B].[dbo].[Names] I should now be able to query the table "Names" from within database "A" ...
1
vote
0answers
41 views

Check if 1/3 Queries Evaluates to True

My large (+100 line) query contains a WHERE filter similar to: select * from (<complex 100+ line query>) d WHERE ( (EXISTS (select 1 FROM TABLE1 t1 WHERE d.dummy = t1.x ...
-3
votes
2answers
85 views

How do I find mismatches in two tables?

I have a database where I'm trying to find inconsistencies across two tables. I'm new to SQL and would like some help. The other questions I've looked up are confusing and too convoluted for what I'...
0
votes
0answers
27 views

Execution time for CONTAINSTABLE/WHERE query

I am facing an issue for a seemingly trivial database query on SQL Server 2012 accessing a full-text index: SELECT MyTable.ID FROM MyTable INNER JOIN ( SELECT [KEY] FROM CONTAINSTABLE(MyTable,...
0
votes
1answer
23 views

design a database which each invoice is made at the end of the month [on hold]

Each customer has different item prices, so i've made 3 tables: CUSTOMER(*customerID, customerName) PRICE(*customerID, *itemID, price) ITEM(*itemID, itemName) But each customer will receive their ...
0
votes
0answers
18 views

Super polymorphic event schema

I want to be able to track every action a user takes on my site. An action can originate from a visitor or a user (both of which are human). An action can affect a subject (visitor or a user) An ...
0
votes
3answers
62 views

Is there a symbol I can use to have a where clause match all columns?

I'm using sql parameter's and I have a query that I'd like to use for two similar queries. The first uses two where clauses the other uses only one of the clauses is there a symbol I can use for the ...
0
votes
0answers
25 views

Query that shows name of excel spreadsheet that is calling the stored procedure

Does anyone know if there is a way to query sql server for the name of the excel spreadsheets in which a stored procedure is being called to produce the data?
0
votes
2answers
34 views

Need to create a “summary grid” query?

I have multiple transaction records in table A like this: TXN# DATE CUSTOMER 1001 10/05/2015 Cust 1 1002 02/03/2016 Cust 2 1003 02/06/2016 Cust 1 1004 03/25/2016 Cust 3 1005 03/26/...
3
votes
0answers
35 views

Concurrent Merge Issues

A (simplified) model of my application has several processes dumping data into the table below: CREATE TABLE [dbo].[InputData] ( [InputId] [int] NOT NULL, [Dts] [datetime] NOT NULL, [...
3
votes
2answers
33 views

ALTER TABLE SWITCH

I have two columns that I want to convert from computed to non computed. I have the code for that. However, it was suggested to me to use the ALTER TABLE SWITCH. I believe the individual who ...
0
votes
0answers
36 views

Linked Server directly to database

Say I have a query like this: select * from openquery ([linkedservername],'select * from [databasename].dbo.person') Is there a way of omitting [databasename].dbo.? I have an enormous query I want ...
0
votes
1answer
35 views

Oracle sql combine several rows of the same table into one row

I have a table where for each given ID, three rows are generated as shown. The first row is the header row: +-------+------+-------+------+-------+----+----+----+ | ID | GRP | ITDESC| DEN | NUM ...
14
votes
2answers
591 views
+200

Does any DBMS have a collation that is both case-sensitive and accent-insensitive?

Note this question is vendor/version agnostic It seems to me, as a speaker (typist, writer) of English, reasonable to expect words to be properly cased but not necessarily have the correct accents ...
3
votes
3answers
261 views

Long running delete query

I have a table with roughly 11 million rows, defined as: CREATE TABLE [sko].[stage_närvaro]( [datum_fakta] [datetime] NULL, [person_id] nvarchar NULL, [läsår_fakta] nvarchar NULL, ...
-4
votes
0answers
24 views

How to populate a value into the null value of two duplicate records, one with some value and the other with the null [closed]

Data: Accnt No: | Trans_id| Amount| Remarks XXXXXXX100 | 501 | 100 | successful XXXXXXX102 | 503 | 5000 | successful XXXXXXX102 | 503 | | successful XXXXXXX103 | 505 | ...
0
votes
0answers
29 views

Subquery or Inner Join?

I have this simple query that finds all transactions from accounts belonging to a specific login, with some extra conditions on the transactions. SELECT t.id, t.date, t.amount, t.description FROM ...
0
votes
2answers
42 views

Slow UPDATE FROM Query in Large Table

I'm currently trying to merge two very large (11 million rows) tables, and my query has been running for over two days with no end in sight. My basic query is: UPDATE us_demand SET ... FROM ...
1
vote
1answer
47 views

Retrieving specific results from a query

I have the following database table Firstname Varchar(40) Surname Varchar(40) Department Binary JobCode Char(1) Normally, pulling the records of a particular department is no problem. The ...
-1
votes
0answers
19 views

some pattern that I can inner join from only one of many kind of tables

I have a very long data form which needs to be saved. additionally, my form data can be separated into 4 kind of form. if I get common columns between 4 types I'll have a table with 48 columns ,...
0
votes
0answers
12 views

Multiple Criteria in Count not working properly

I am trying to create a count query in Access 2010 that counts a column where the parameter Spot in the CityData table is equal to 'Y' and where the last entry in the FeedOut parameter in the ...
0
votes
0answers
20 views

How to return columns when using Dynamic Sql

In my project, i want to search input values and i think i should create a SP using dynamic Sql. When i call this SP in MVC, it return "int".I want it return columns as ProductName,ProductCat ... . ...
0
votes
1answer
20 views

SELECT records based on return of COUNT query

I would like to create a query that returns records if values in a column occur more than once. I came across other Stack Exchange questions but these only dealt with returning the number of ...
1
vote
1answer
34 views

Use stored procedure to get minimum value from column and decrement it and other values

I'm trying to understand how the following algorithm could be completed in SQL 2008 R2. I have a table that contains production data. The table uses a "rolling" scheduling method, meaning that orders ...
5
votes
1answer
39 views

Recover Instance after Log File disk error

This is mainly theoretical, but I would like to have a documented list of options if this happens in the future. Today we had a critical disk error on the SAN, meaning the disk holding the ...
0
votes
0answers
78 views

SQL query runs fast on local computers but slow on production server

I am running a fairly basic query on my local development machine which runs almost instantly. However on the server its taking around 3-4 seconds to return results. I have ran Client Statistics on ...