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

learn more… | top users | synonyms (2)

1
vote
3answers
37 views

SQL trigger when a row is updated question

My problem is as follows. I an creating a SQL database for a company that whenever a row is updated on the DB i want to have a trigger that calls a cURL request to transfer the updated information to ...
0
votes
1answer
56 views

Generate a column from different rows in sql

I have a table that looks like this: SKU DateOut DateIn Status 123 1/2/2015 5/2/2016 1 123 10/2/2016 18/2/2016 1 123 ...
0
votes
0answers
23 views

Paging through data that is frequently changing

When users are browsing pages of data where the data keeps changing, what is the best way to control this so the user experience is not impacted. If I browse catalog of 100 records with 10 per page, ...
1
vote
1answer
122 views

SSIS: To run the package outside of SQL Server Data Tools you must install expression task of integration services or higher

Me and my colleague using the same version of .Net framework (4.5) and installed SSDT in visual studio 2013. He prepared a package (not so complex) and can able to execute the same from SSDT without ...
3
votes
2answers
82 views

What are options for super volatile tables?

I've inherited a very volatile table which is a map of who holds what resource in the system. At any given moment, there could be a dozen inserts/deletes/reads going against that table. However, ...
0
votes
3answers
37 views

Repository for organizing company SQL statements?

We have a few people here that use SQL and have quite a few queries we each individually use and share. I'm wondering if there's a solution to store all of these statements in a central repository ...
0
votes
1answer
27 views

Query - Pivoting 2 columns into 2 rows

I am familiar with PIVOTS but have done only simple ones of one column into a row. I have this query: DECLARE @EndDate DATE SET @EndDate ='20160728' --{?EndDate} SELECT T1.ItemCode,SUM(T0.IssuedQty)...
0
votes
1answer
53 views

How to manage SQL Log File .ldf [duplicate]

My problem is having issue with SQL Server 2014 Database and its size growing and consuming Hard disk is almost full, Only 50GB space is left in 1TB Hard drive, and SQL database log (.ldf) file is ...
1
vote
1answer
22 views

correlate subquery in hive

SELECT ndo.sku ParentSKU, visitsWhenSKUWasOnline.s FROM Temp.NumberOfDaysOnline ndo JOIN ( SELECT SUM(gasessiondata.sessions) as s FROM gasessiondata WHERE gasessiondata.date >= ...
0
votes
0answers
19 views

Structure a database for a Blog

I built a database for a blog. I am a student yet, so my knowledge is limited in this area. I post this question to get a briefly description of what I do wrong, why, and how I can fix it. I'm not a ...
6
votes
1answer
27k views

Converting XML to MySQL tables

I have a large XML file in the following format and I need to convert this file into a MySQL table. Please let me know how can I accomplish this? ~~~~~~~~~~ <host starttime="1392325468" endtime="...
5
votes
2answers
27k views

Could not allocate a new page for database because of insufficient disk space

Using the SQL Server Import and Export Wizard, I get this error: Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. ...
1
vote
0answers
69 views

Performance issue with larger resultsets SQL Server

I currently have a stored procedure in SQL Server where I execute a SELECT statement multiple times based on the variables I pass to the stored procedure. The stored procedure counts how many records ...
0
votes
2answers
314 views

Select all from table using procedure oracle

I am trying to execute the select command in a procedure.Initially i retrived all of the columns of the table in the procedure using cursor. The real problem comes when I am trying to access the ...
0
votes
1answer
38 views

Execution plan - Hash Match

SELECT dbo.Contracts.ContractID AS [Service Unit ID], dbo.Jobs.JobName, dbo.Customers.CustomerName, dbo.Contracts.ContractAutoID, dbo.Contracts.ContractType, dbo.Contracts.ContractStatus AS [...
0
votes
2answers
27 views

What is the best way to backup logs and shrink logs in SQL Server 2008 r2?

What is the best way to shrink and backup our db logs? I have seen many DBAs that do it : ALTER DATABASE [mydatabase] SET RECOVERY SIMPLE DBCC SHRINKFILE(<log_file_name_Log>) ALTER DATABASE [...
-5
votes
0answers
41 views

oracle sql developer [on hold]

i have two main tables out of many tables. i just want to get the data on the year 2004.but it only executing without any output on it.i don't know if my script was wrong because it's just been a ...
0
votes
1answer
15 views

How to query two values from the same table from different records combined with fields from other tables?

I have a query similar to the one below which is getting data from a couple of tables and works as expected. The table eventsink.RedEvent has another column called Finished. I want to add the Finished ...
1
vote
1answer
36 views

How to use Case Statement with BCP

I am using BCP as follows, bcp "SELECT * FROM [dbo].[GpsPoint] where id in (551043, 551044, 551045)" -n This works 100%. I have omitted the rest of it because it is just server, user, password ...
0
votes
3answers
30 views

Table concatenation

I want to have a dynamic query that I can concatenate my table based on current month. I want to have a variable to my FROM and JOIN statements. DECLARE @month_number AS VARCHAR(2); DECLARE @...
1
vote
2answers
145 views

SQL Server restore database file access error

I am trying to restore a database from a file on a remote machine. The script I am using is as follows: RESTORE FILELISTONLY FROM disk = '\\server\path\to\file.dmp' RESTORE DATABASE MyDB FROM ...
0
votes
1answer
2k views

Restoring database backup file gives access error

I am running SQL server 2008 and trying to restore from a backup file. Note: the backup file and folder and read/write access to "everyone". Running the command as "master" Running RESTORE ...
1
vote
1answer
20 views

Many-many relation with specific type

Sorry if this question has already been asked, but I didn't find it performing a search. I have 2 tables (table_a and table_b), linked by a many/many relation. The relation can be of two types, ...
0
votes
1answer
23 views

Help needed in creating a SQL statement containing four joins

Please help. Given a studentID and a TagNumber i want to get the UserID related to that TagNumber. The difficult condition is that TagNumbers can be duplicate within a Users table. So we can pinpoint ...
0
votes
1answer
23 views

I am trying to run this code and I get an error at line 11 [on hold]

CREATE TABLE IF NOT EXISTS `tblproduct` ( `id` int(8) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `code` varchar(255) NOT NULL, `image` text NOT NULL, `price` double(10,2) NOT ...
1
vote
2answers
35 views

Select if colA='A1' is followed by colA='A2' [SQL]

I have a set of entries like: Id ColA 1 A1 2 A2 3 B 4 A2 5 A1 6 C 7 A1 8 A1 9 A2 10 D In pairs 1, 2 and 8, 9 the first line has A1 in colA and the following line has ...
0
votes
1answer
39 views

Which is more efficient: A join or a group by?

I've got a table A with a relation to another table B, where each A row has two rows in B. I want to extract all the values from a specific column in B for each row in A. Ignoring the difference in ...
0
votes
0answers
55 views

SQL Server Deadlock

I am running SQL Server 2012 Service Pack 1 + Non Security Update (KB2793634). I am frequently getting deadlocks occur, 99% of the time with the same 2 queries. How can i prevent this deadlock from ...
1
vote
2answers
37 views

Finding the row with the latest date for each row type

I've got an SQL database (SQLAzure V12 version running on Azure) that looks like the following: DECLARE @VehicleData TABLE ( id int PRIMARY KEY, Registration nvarchar(50) NOT NULL, [...
0
votes
2answers
34 views

How to join to the same table multiple times?

I have two tables, "hierarchy_table" and "name_table". The hierarchy table contains an object which has multiple parents and children. Each parent and child is referenced by id. | object_id | ...
0
votes
0answers
11 views

Counting entites based on status in rolling interval

Given the following table: CREATE TABLE status_log ( entity_id bigint NOT NULL, user_id bigint NOT NULL, status character varying(128), "timestamp" timestamp(6) without time zone ) I want ...
0
votes
1answer
124 views

Count for many-to-many relationship

I have the following tables: surveys properties owners_properties owners ---+------------ ---------- ------------+--------- ------ id | property_id id ...
4
votes
1answer
387 views

How can I prevent having inconsistent data under isolation level serializable in Oracle SQL?

I have the following table: InStores +--------+---------+-----+ | ProdID | StoreID | qty | +--------+---------+-----+ | p1 | s1 | 25 | | p1 | s2 | 70 | +--------+---------+-----+ ...
1
vote
1answer
29 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 ...
0
votes
0answers
9 views

regarding creating two colums using the CONCAT and CONCAT_WS function

Complete newbie here using SQL. Sorry if i don't make much sense here. Basically i'm trying to combine fields on a database that would keep customer's details. For example: fields: customer_title,...
0
votes
1answer
41 views

how to take output from second table by joining in SQL [on hold]

table 1 table 2 id Name value id status 1 a 1000 1 open 2 b 2000 2 closed 3 c 3000 ...
0
votes
3answers
37 views

How to select duplicates into new columns?

I am trying to select distinct data in new columns! My Table productID | imageURL 1 | a1.jpg 1 | a2.jpg 2 | a3.jpg Target Table productID | imageURL1 | ...
0
votes
0answers
15 views

Select all from table where ColA equal to (get list of ColA values that correspond to ColB = 'NOT') [on hold]

I have an SQL table that has entries like: RuleID Symbol 1 OR 1 123 1 363 2 AND 2 847 2 287 3 AND 3 NOT 3 234 3 ...
0
votes
0answers
54 views

SQL Query to calculate total time worked and total distance travelled

I am trying to write an SQL Query which calculates the Total Time worked and Total Distance Traveled by a Driver for each date. The StartOfDay is the MIN(LogDateTime) WHERE EventCode = 1 The EndOfDay ...
2
votes
1answer
55 views

How to show when loan was paid off

First time posting but have been a reader for over 10 years. I have a need to show when a loan was paid off regardless of the rolling balance from refinancing/taking out additional loans. In the ...
0
votes
2answers
248 views

Selecting Only One Record with Most Recent Date Using Table Join

I have a list of 463 CARRIER_CD. I am attempting to retrieve the most current BILL_DT for each of the 463 CARRIER_CD. I have uploaded the 463 unique CARRIER_CD to a database named edw_sbx_bt the ...
0
votes
0answers
30 views

Split string and and compare parts in WHERE

I had table with string column like 'One Two Three'. A need to split this string by space and use parts in WHERE clause. For example: SELECT * FROM records WHERE regexp_split_to_array(client_name, ...
1
vote
1answer
18 views

How to avoid Msg 9514, Level 16, State 1, Line 3 error for linked server?

I have a query to compare data between my local SQL Server and linked SQL Server. My problem is that the table I compare contains XML column. I get: Msg 9514, Level 16, State 1, Line 3 Xml data ...
1
vote
1answer
37 views

I need to merge two queries with condition

I have the following query: SELECT URYRR_FORWARDS_REC_H.CB_LINE as "CB_LINE", URYRR_FORWARDS_REC_H.CB_LINE_DESCRIPTION as "DESCRIPCION", URYRR_FORWARDS_REC_H.UYU_BALANCE_FW as "MONEDA LOCAL", ...
-3
votes
1answer
44 views

Finding the mismatch column names

I have two datasets, both having same column names and just one row. I want to display the column names for which there is a mismatch of column values. Could anyone please suggest how this can be done....
26
votes
7answers
16k views

How do I copy a table with SELECT INTO but ignore the IDENTITY property?

I have a table with identity column say: create table with_id ( id int identity(1,1), val varchar(30) ); It's well known, that this select * into copy_from_with_id_1 from with_id; results in ...
2
votes
1answer
3k views

Sybase SQL Anywhere 12 - Get all indexes which are unique -> ambigious sysindexes error

we are using a Sybase SQL Anywhere 12 db. In the db there are indices, which are unique, but shouldn't be unique. Therefore I search for a quick way to list all tables with unique primary keys. I ...
0
votes
2answers
22 views

SQL Server - Select last value given a date

To make it easier, I have data that looks like this as an example: What I am trying to return is the Amount of the Balance Update as of a specified Date for each Investor_ID. For example, if my ...
15
votes
2answers
623 views

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 ...
-1
votes
0answers
17 views

How to use count and groupby to create many columns [on hold]

I have a simple table named A with 3 columns: product_id first_date second_date. If first_date==second_date then up_to_date. if first_date<second_date then nearly_over_date, else over_date After ...