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

learn more… | top users | synonyms (2)

0
votes
0answers
13 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, ...
-5
votes
0answers
37 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
5 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 ...
0
votes
2answers
13 views

¿what is the best way to backup log and shrink log SQL Server 2008 r2?

What is the best way for shrink and backup our db log? I have seen many DBA that do it : ALTER DATABASE [mydatabase] SET RECOVERY SIMPLE DBCC SHRINKFILE(<log_file_name_Log>) ALTER DATABASE [...
1
vote
1answer
33 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
1answer
14 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
3answers
20 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
138 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
2answers
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
18 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
17 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
36 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 ...
1
vote
0answers
51 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
0answers
37 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
53 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
30 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
28 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
7 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
40 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
53 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
244 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
36 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
43 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
619 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
16 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 ...
4
votes
2answers
149 views

Update old database with SQL dump

I had to recover a database with a some months old full backup. I have however in my possession a most recent but unfortunately incomplete SQL dump for this same database done with mysqldump. Is ...
0
votes
0answers
11 views

SQL Sum column til value and then increment group and continue summation

I've run across an interesting problem that I'm not sure how to tackle. I've been charged with finding a solution to the following scenario, and I'm not really sure where to go with it. Here is the ...
0
votes
1answer
29 views

SQL Server: Msg 512, Level 16, State 1, Subquery returned more than 1 value

This has me baffled, as I have tested multiple variations of the correlated subquery to no avail. Since the MAX function is suppose to guarantee a single result, I'm almost convinced that the problem ...
0
votes
0answers
17 views

UNION Query rendering 2 columns

I am using Access 2013 SQL. I have the following query qry structure: SELECT TOP 10 [Sub Category] AS Category_1 FROM tbl WHERE [Category]='1' GROUP BY [Sub Category] ORDER BY SUM([Value]) DESC; I ...
0
votes
1answer
29 views

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

I need to verify data between an 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
0answers
16 views

Can SSMS or SSDT validate and insert security objects? [on hold]

Can Sql Server Management Studio validate and insert security objects (roles, schemas, asymmetric keys, certificates, users, and so on) both at the server and DB level?
0
votes
1answer
50 views

Database design considerations for unused columns with 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
16 views

I want to make a website similar to Udacity, Coursera e.t.c. for online courses. Which technology should I use for storing the course information? [on hold]

I am mainly confused between storing the information of a certain course in an SQL Database A JSON / XML file for each course which will then be stored in a file storage system and can be retrieved ...
1
vote
1answer
62 views

Joining Tables in the FROM vs. the WHERE clause [duplicate]

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 ...
-2
votes
2answers
93 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'...
-1
votes
1answer
19 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 ...