Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

-1
votes
0answers
11 views

Clustered Index Secured Views and FK questions

I have couple of questions about different things: 1. If the table doesn't have any Keys or PK defined, but it has a clustered index that have 4 unique columns, would that considered to be the ...
0
votes
0answers
31 views

Split Excel row with sql

I'm storing some data with this SP from a xls file. The fields are separated by " \t " , but recently I have been receiving files without escape sequencers. I need to find a new way to split my ...
0
votes
1answer
16 views

Splitting array of string values into Rows Numbers Table Ref Error

I am trying to create a table that queries individual database records, but splits out values from an associated array into individual rows for the individual database record. So far I have created ...
1
vote
1answer
40 views

Simple recursive CTE stuck in infinite loop

I have a need for a recursive query to find daisy chained related data. I have the following query CREATE TABLE #source (Parent varchar(10), Child varchar(10), Date datetime) INSERT INTO #source (...
-2
votes
0answers
18 views

Update column based on value in a different table

I am trying to update columns with counts based on values in another field. I have tried a couple of different things but am not getting the results I expected. First, I have created an update query ...
-1
votes
0answers
29 views

Variable Columns in SELECT Statement - Is there a way?

I'm frustrated. I need to export data from an existing database. Is there a way like SELECT tbl1.*, [SELECT THE ADDITIONAL FIELD NAMES FROM tbl2] FROM tbl1 as A LEFT JOIN ( tbl2 INNER JOIN tbl3 ...
1
vote
1answer
44 views

Generating maintenance database from maintenance tables currently in master and msdb

I want to create a maintenance database that i can clean up master and msdb, i am trying to collect all the table info from master and msdb that are not Microsoft tables, bearing in mind that some ...
-3
votes
1answer
41 views

Updating a string field by concatenating 2 int columns

I have 2 columns, an int and a tiny int, and I want to update another column, a varchar one, with the value column1 + '-' + column2. Something like this pseudo code: UPDATE COLUMN3 varchar = CONCAT (...
-4
votes
0answers
14 views

Cron Expression into words in SQL server [on hold]

Hi I have a table where value stored in cron expression as below 30 04 * * THU 00 06 * 3 SAT#3 30 04 * * SUN 30 04 * * TUE 30 04 * */1 SAT#1 30 04 */1 * * 30 04 * 4 SAT#4 30 04 * */3 SAT#1 Now I ...
-1
votes
2answers
43 views

SQL Server, Error: Msg 22050, Level 16, State 1, Line 0 Failed to initialize sqlcmd library with error number -2147467259 [on hold]

I have the below query results to attach and email: ----------------------------------------- EXEC [msdb]..sp_send_dbmail @profile_name='SMTP', @recipients='xxxx@yyy.com', @subject='DB Mail', @body='...
0
votes
0answers
14 views

How to set up a replication from a publisher to an always availability group with two replicas and a listener

There is a publisher that plays the distributor role, too. A database on the publisher is supposed to be replicated (Transactional Replication) to both replicas of a remote always-on availability ...
0
votes
1answer
42 views

Instead of C:\SQLDBA\ServerName\Instance rather C:\SQLDBA\ServerName_Instance

I am trying to create a folder based on the servername\instance to backup up to, i want the folder to create as servername_instance. Could you please point out where i am going wrong as it creates as ...
1
vote
1answer
44 views

Script SQL Server Agent jobs to file

I am busy making a backup of all Agent Jobs by scripting them all to file.`How would i rewrite the below to use BCP instead BEGIN SET @EchoCommand = 'ECHO ' + @EchoField + ' >> ...
0
votes
1answer
20 views

Choose record based on varying condition

I have a table that a primary key that can have one to two different status' associated with it. It looks like this: Key Status 123 Book 123 Change 122 Book 121 Book 121 Change If there is a record ...
0
votes
1answer
52 views

Inner Join until null on self-referencing tables

I have the following SQL Table: OrganizationalUnit ID - PK ParentOrganizationalUnit - FK Title Department_Code (optional) Division_Code (optional) Person ID - PK ...
0
votes
1answer
23 views

MariaDB order by before Group by

I have looked around at other solutions, but none seems to work quite right. What I am trying to do is to get the latest result (sorted by date) from a selection, grouped together by sample. Here is ...
0
votes
3answers
51 views

Combine same field from multiple rows into one row

I am joining two tables HR and UserDefined based on the Employee_ID: HR Table First Name Last Name Employee_ID Joe Smith 456654 User Defined Table Area ud_1_text ud_2_text ...
2
votes
1answer
46 views

How to narrow down records in SQL based on conditions

Customer Rank Joining_date salary A 2 2017-10-12 500 A 1 2017-10-10 800 A 1 2017-10-20 400 B ...
1
vote
2answers
29 views

Saving SSIS package from server to local computer

Right now I'm able to upload an SSIS package from my local computer to SQL Server with my C# program: Microsoft.SqlServer.Dts.Runtime.Application app; app = new Microsoft.SqlServer.Dts.Runtime....
-1
votes
1answer
24 views

Converting unix timestamp to an sql timestamp in postgres

I have passed Date.now() and other plain unix timestamps like 1534360109480 into sql and ran them through this. "@converted_date" = to_timestamp("@date") AT TIME ZONE 'UTC'; And it consistently ...
0
votes
1answer
56 views

Need help figuring out a daisy chain issue [closed]

We have a goofy process (don't we all?) that daisy chains (or cascades) on a table that needs flattening out for our data warehouse. The field "alt_key" is an identifier field. It ends up being the ...
-5
votes
0answers
23 views

Permissions removed automatically [closed]

We expect transaction flow from till to SQL Server (the middleware transportation software is mulesoft), but all of sudden Mulesoft account permissions revoked, we need have to re-generate access to ...
0
votes
0answers
19 views

How to design database for storage of Items in Inventory stores? [closed]

This is basically for a Production Management System that I'm currently working on. I have more than one type of Items to store in inventory (Products/Parts/Materials). I want to store them in ...
0
votes
1answer
14 views

Get name column instead of ids from two foreign keys

I need to get both group names as a result, although I have no idea how to do this query. Table 1 (groups) +---------+--------+ | id | name | +---------+--------+ | 1 | newb | | 2 ...
1
vote
3answers
849 views

How to delete duplicate records in MySQL, in a table without IDs?

I need to delete the duplicate records in this table. However, there is no id for each row. Example Data +---------+--------+----------+ | product | amount | quantity | +---------+--------+----------...
3
votes
0answers
23 views

Best DB architecture and querylanguage for a given application [closed]

I have many external databases. Some MSSQL some MySQL and Some oracle. We are creating an RFP to create a web app to create reports that rely on data from all of these sources. I suggested creating a ...
0
votes
2answers
34 views

Calculate ticket sales by using SUM in SELECT clause

In this ticketing setup on dbfiddle, I am trying to calculate the ticket sales for a particular event by multiplying the ticket price and the total number of tickets sold for that event, based on ...
0
votes
1answer
13 views

Sort products by image first and by name ASC

I have a table with products, some products have images, some of them don’t. I have to sort these products by name ASC but first products should be these with an image (field isn’t empty string), and ...
0
votes
0answers
23 views

Group 5 most visited locations

I've got a table in a MySQL database with thousands of check-ins from a GPS tracker. Every x seconds, a new location check-in is inserted. This is how the table looks like: +----+-----------+--------...
0
votes
0answers
38 views

Transaction log shipping

I have transaction log shipping set up from my primary server to my secondary server. This morning, the LSRestore job failed due to insuffient drive space. The logs were still available on the ...
0
votes
2answers
33 views

Find out recovery model changes

I'd like to work around instances where a database were changed to simple and then reverted back to full or bulk logged recovery models. This is for my backup maintenance plan, as obviously any ...
6
votes
1answer
499 views

Left join without duplicate rows

I have two tables called record and record_history. For each record, there could be more than one history. They can be joined by id and record_id. I want to get all the record's entries with recent ...
0
votes
1answer
34 views

How to list all constraints of a table in PostgreSQL?

How to list all constraints (Primary key, check, unique mutual exclusive, ..) of a table in PostgreSQL?
-2
votes
0answers
21 views

how to use left join in LINQ c# [closed]

I have a query T-SQL, now, I want use it in LINQ, that mean I want convert this SQL query to Linq. Help me Select u.[USER_NAME], u.PHONE, a.APARTMENT_NAME, c.CA_NO, c.CA_NUMBER, c.CA_ID, ct.CT_NAME, ...
-1
votes
0answers
54 views

How to limit SQL Server sessions based on hostname? [duplicate]

When I run sp_who, I can see the information about current sessions. I need to limit that sessions according to hostname. For example, I need to say the host named x can only have 1 session at a ...
-1
votes
0answers
20 views

SQL Server Always ON Availability Group Licensing [closed]

I always get confused with SQL Licensing. I am planning to setup a SQL Server 2016 Always ON AG with two nodes. One at the main office and one at the DR. I have on enterprise edition license with ...
1
vote
1answer
33 views

How to reference primary key when inserting in MySQL

I have a database containing the tables authors and books. I don't know how to correctly assign the foreign key in the books table. I read the information provided in this link and have constructed ...
0
votes
0answers
24 views

Looking for a way to get top results by each year

Complete SQL rookie here I have a Database with Products, Sales and Dates. I need to extract the top 10 sales by year on a specific date and rank them by sales by year, to get something like this: ...
1
vote
3answers
70 views

Return a value only when conditions satisfy for entire column

Can anyone help me to how to achieve below result Input data ORDER_NUMBER LINE_ITEM FLAG LP-13288 1 TRUE LP-13288 2 FALSE LP-13288 3 (null) LP-13288 4 FALSE LP-13289 1 ...
0
votes
1answer
22 views

Why does json_agg fail with error “function json_agg(record) does not exist”?

With postgresql version 9.2, I'm trying to run a query that selects certain columns to build a json object. Here's the query, which I derived from this question: select a.id , json_agg((SELECT x ...
0
votes
1answer
28 views

Clone SQL Server databases [closed]

I have a 2 databases on 2 servers, Server A db1 and Server B db2. Db 1 is a clone of db 2 from 2 weeks ago, and was never updated since then. There is a short way to make db1 exactly like db2?
-1
votes
0answers
24 views

Parent id and child id concept [closed]

This about parent id and child id concept. Thanks in advance Table 1 id | name ------|---------------- T1 | zzzmmmnnn Table 2 id | name -----|--------- C1 | zzz C2 | mmm C3 | nnn ...
1
vote
2answers
28 views

Any benefit in running ANALYZE after bulk insert in table with only PRIMARY KEY index in SQLite?

If I create a table in SQLite that has only the PRIMARY KEY index, is there any role for running ANALYZE after a bulk insert, or will that key automatically have been kept up-to-date by necessity? In ...
-2
votes
0answers
18 views

Create Table error PostgreSQL [closed]

Hi I am receiving an invalid syntax error when I try to create this table, any help would be appreciated, thanks! CREATE TABLE Opportunities ( OpportunityID varchar(50) DealNumber integer, ...
1
vote
1answer
24 views

Getting Failed (exit code: 1). when running restore DB from a .tar file in pgAdmin4 postgresql 10.5 [closed]

I'm taking an intro to SQL course and I can't get my very first database loaded. I have a file dvdrental.tar, I create a new database dvdrental > right click > Restore > Select File > Pick "Data" ...
1
vote
1answer
52 views

Unexpected results in query with rownum condition [on hold]

I have found old query in application that behaves unexpectally after Oracle update. I have found out that problematic part of this query is condition: rownum >= 1 When I apply this condition, ...
2
votes
0answers
24 views

SQL Server: Replicated transactions are waiting for the next Log back up or for mirroring partner to catch up

I have two SQL Server DB instances on the same machine with one hosting a replica of the other. In addition, I have transaction replication setup for all tables on the main instance to the replica. I ...
-2
votes
1answer
35 views

Command analog in MS SQL [closed]

I'm rebuilding the database from mysql to MS SQL. In mysql such a design exists in procedures: DECLARE CONTINUE HANDLER FOR NOT FOUND SET finish_cycle = TRUE; OPEN cur; SET finish_cycle = FALSE; ...
1
vote
2answers
27 views

Add cumulative sum to time-series query PostgreSQL 9.5

I wrote the query that gives me time-series over some date range and interval that shows revenue for each time interval: SELECT interval_date, coalesce(campaign_revenue,0) AS campaign_revenue,...
0
votes
0answers
20 views

Duration of consecutive timestamps by group in sql

I am new to psql window functions and would like to perform a query on test_table in order to find out every instance of inactive outages per mobile_id, country, and brand and most importantly the ...