DO NOT USE this for questions targeting Microsoft SQL Server, use the tag sql-server instead. "SQL" is an acronym for "Structured Query Language", it is used in relational database management systems (RDBMS) to query, update, delete, and insert data as well as modify the structure of the database. ...

learn more… | top users | synonyms (1)

0
votes
0answers
22 views

http vs sql queries [migrated]

i have big problem deciding what approach to take, i have many pages on my site that uses tabs. for example a page with 5 tabs (horizontal tabs). now every tab takes data from different table in the ...
0
votes
0answers
33 views

How can I write a query to aggregate multiple strings into one field? [migrated]

I am trying to merge three tables. The first table has id and data_name, second table data_id, option_id and property, third table user_id, data_id. For example: first table +----+-----------+ | ...
1
vote
1answer
18 views

Select Distinct on subset of columns, name different set of columns to return

I am using PostgreSQL and have two tables: Table_A colA | colB | colC | colD | colE | colF | colG | colH | colI | colJ Table_B colA | colB | colC | columnD | colE | columnF | colG | colH | colI | ...
0
votes
0answers
15 views

SSMS SQL Server 2014 - Selecting BackupSets for a Restore takes a long time

I'm having an issue with SSMS SQL Server 2014 (before and after SP1). When I go and select 'restore database' from the server and select a database, it just sits there and spin and spins. More than ...
0
votes
0answers
5 views

Part of query is not properly performing in access design view(2010)?

So, I have been trying to figure out why this query is not running in the design view properly. I am trying to create a list of IDs of individuals who have an invoice(Gift table) between 1/1/2014, but ...
-1
votes
0answers
44 views

Need Review - Index Rebuild and Index Reorganize strategy?

I've written a block of code to design Index Reorganize and Index Rebuild strategy based on following recommendation. I'm considering only Clustered and Non-clustered index, not Heap. Does anything ...
0
votes
3answers
30 views

Error trying to SET a field when two fields in different tables match

I am trying to set catid to 584 whenever the rows in the tables ykz2d_crmery_deals and ykz2d_maps_integration have the same company id using the following query: UPDATE ykz2d_maps_integration SET ...
0
votes
1answer
24 views

Showing all values when at least match a given one

Given three tables items, genres and itemGenres; how can I filter out the items that have at least the given value while also outputting the rest of its genres. With this data INSERT INTO items ...
0
votes
1answer
42 views

Filter from the same user times

i have a table with user id-s, and many times for the same users, like this: id time 1 13:00:01 1 13:00:01 2 13:00:09 1 13:00.23 1 13:00:24 2 13:00:11 2 13:00:11 I ...
0
votes
2answers
28 views

SQL Server DB Restore Unable to browse directory

I have a problem with SQL Server 2008. When I try to restore a backup (located in the default location). This error appears. Cannot access the specified path of file on the server. Verify that you ...
2
votes
2answers
37 views

How can I Search for a string in all fields across all tables of a MySQL database?

I want to find a string and I don't know exactly which column and which table. How can I find it? Thanks.
1
vote
0answers
24 views

Count query help needed with unique records [migrated]

I have this following data-structure and I am trying to find unique ID where value Alphabets value Equals to A and B (i.e. select ID = 1, but not ID = 3 or 5). and also find unique ID where value ...
0
votes
2answers
38 views

Retrieve Data from a Specific Database [closed]

Goal: I want to retrieve the value of [data].[Mobiles] when you use a query document that is for the database [test] (use [test]) Problem: Based on picture two, I cannot retrieve the value ...
0
votes
0answers
11 views

Oracle: Recursively self referential join with nth level record

I have self referential table like this: id |level | parent_id ---------------------- 1 |1 |null 2 |1 |null 3 |2 |1 4 |2 |1 5 |2 |2 6 |3 |5 7 |3 |3 ...
-1
votes
2answers
26 views

SQL: Find row number with column entry of a specific string [closed]

I'm have an MS SQL Server 2014 Express database which I can search using a PHP script on my server to find if a string exists in the database. My SQL code is: IF EXISTS (SELECT * FROM TABLE WHERE ...
1
vote
2answers
48 views

SQL Server : trigger FOR DELETE

I want to create a trigger, which does not delete a customer if his name is Peter. How can I do that? CREATE TRIGGER trgCUSTOMER ON customer FOR DELETE AS BEGIN IF (SELECT name FROM deleted) not ...
0
votes
1answer
27 views

How to find the affected tables in a database? [closed]

I need to see the tables in the database that are affected after some changes are made from the front end application.
0
votes
2answers
62 views

How can i update my database from another database using temporary tables?

I want to update tables of my database using another big database every day with using temporary tables and without returning result. How can i update it? This my temporary table : use data_pro; ...
0
votes
4answers
44 views

Insert from Another Table + Removing Duplicate Entries in Postgres

I'm trying to insert data from one PostgreSQL table to another while removing duplicate entries but I'm having some trouble with the code. I have two tables I'm working with: mytesttable, which ...
1
vote
2answers
72 views

Group by month and year given yyyy-mm-dd as a date

I have a list of incidents and dates along with them, yyyy-mm-dd then a category. I need to order by the category (speeding tickets, DUIs, etc...) for each month in a year. This is what the two ...
7
votes
3answers
514 views

Use 'default value' in table when NULL

I am building a config table and want one row to be the default value. For the example, I have a list table of all my databases and a msg table of my return values. In the msg table, I have one row ...
2
votes
2answers
42 views

Query Row Count for All Tables

I need help creating an MSSQL query to pass in every table name to the query below, which returns the number of rows. This is how I get the row count for a single table: SELECT Total_Rows = ...
1
vote
1answer
22 views

To find out the sum total of GRNQty and GRNValue of particular item from column 1

Query 1 # SELECT spi.Item,spi.ItemName,supdd.PackageID,spi.Specifics,iteb.brandname,supdd.Qty AS GRNQty,supdd.GP AS UnitPrice,(supdd.Qty * Supdd.GP) AS GRNValue FROM suppdeldetail AS supdd ...
2
votes
1answer
45 views

How to use a view to span two tables that are identical

We have table A that receives data from our shop floor and we currently have it so that the data is moved from table A to table B after 5 years. I want to streamline this but need help creating a ...
2
votes
0answers
61 views

Weekly SQL database backup failing

I have a weekly SQL database backup job that is failing. If I look at the end of the history of the job, I see the following messages: Executing query "USE [msdb] ".: 2% complete End Progress ...
4
votes
0answers
86 views

Why is query thousands of times slower with DESC?

I have a PostgreSQL database (AWS RDS) and ran the following queries in psql: livenet=> EXPLAIN ANALYZE SELECT * FROM outputs ORDER BY height LIMIT 10; Limit (cost=0.57..36.82 rows=10 ...
1
vote
2answers
35 views

Join Two queries with different declarations

I need to join two different queries to get some columns from both. The first one has a CTE. Query1: WITH StatusChanges AS ( SELECT HistoryID,PartID,Status, DateAdded, ...
-2
votes
0answers
10 views

I want to move the listbox one to another listbox and update the particular listbox value [migrated]

Here, Below i used the code. I am new in VBA. I am trying to move the one list box to another listbox, but I am not able to update the database table. I am struggle on few days. Why this error came ...
0
votes
1answer
34 views

How to make sum of minutes into (Hours : Minutes) format

How to add (sum) two fields (Data Type=Money) into hours:Minutes format Query: SELECT ( SELECT ISNULL(SUM(action.service_time), 0) AS Expr1 FROM dbo.act_reg AS action INNER JOIN dbo.act_type ...
2
votes
0answers
40 views

Select number of records until the sum is less than 'n' - Access SQL

I am working in Microsoft Access. My requirement is: user will give any percentage value and I have to find the number of IDs which form the percentage of the 'Value' column. For eg in the below ...
0
votes
0answers
35 views

Update a column in table only if a condition is met for number of values for a field in other table

I am trying to figure out how to achieve the following (This is simplified version that ignores non relevant columns) I have table "Item" with columns item_id business_key I have another table ...
1
vote
1answer
46 views

To find data in Multiple tables and delete it?

I am using a PostgreSQL server. Suppose I have 200 values in a master table that need to be deleted. There are 9 other tables referencing this master table. The other 9 tables not only reference the ...
2
votes
1answer
46 views

Query to determine start and end dates based on time overlap

Given the following data: id | user_id | started | closed | dead ------------------------------------------------------------------------------------------- 7714 ...
0
votes
1answer
14 views

SQL BCP Utility Writing to SSMS Insead of .csv File

I have a stored procedure in SSMS call sp_testInventoryIssues as follows: USE [ADMIN] GO /****** Object: StoredProcedure [dbo].[sp_testInventoryIssues] Script Date: 06/19/2015 16:02:29 ******/ ...
0
votes
0answers
25 views

How to Create a Recommended Test Planning in SQL Server

Goal: Make lots of different test for a specific stored procedure named 'sp_test' in order to review if you are retrieving the same data based on data input. Purpose: If you have made lots of ...
-1
votes
1answer
22 views

New to SQL- Delete First and Last Day of Each Month From Data Set [duplicate]

I am extremely new to SQL. I am operating on SQL Server 2012. I am working with an Inventory file that contains the Date the Inventory was taken, item #, and quantity. The first and last day of each ...
4
votes
2answers
99 views

Cummulative Sum with Reset Value

Consider the following table: ID | GROUP_ID | ORDER_VAL | RESET_VAL | VAL ---+----------+-----------+-----------+----- 1 | 1 | 1 | (null) | 3 2 | 1 | 2 | (null) ...
0
votes
2answers
43 views

Use column alias in GROUP BY

I have a query where I chain two columns. Why does the alias not work in the GROUP BY clause but in ORDER BY clause, it does work? How can I write the select correctly? SELECT KOS_VER_ID AS ...
1
vote
1answer
49 views

Is there a way to add a column to a table without affecting performance?

How do you add a column to a table in production without affecting its performance? Or is this impossible? I'm asking about Postgres.
1
vote
5answers
77 views

TSQL insert table using view — performance issue

I have a big view joining multiple tables that in a regular basis materialists itself into a table (this step occurs for viz's tool read a table instead of a view during data source refresh): select ...
0
votes
1answer
40 views

How to select users that doesn't in the role

I have 4 roles which are Admin, Procurement, Accounting, HR roles and 3 tables which are Users, Roles and Userroles. They user can have many roles as well as the roles can have many users. the problem ...
1
vote
2answers
88 views

Why is my query returning an unexpected result?

Here are the tables I am using: parts(pid,pname,color) suppliers(sid,sname,address) catalog(sid,pid,cost) I need to find the name of suppliers that supply two different parts with the same ...
2
votes
2answers
45 views

Calculate number of consecutive years (not gapless)

I have a request that wants to look at numbers of consecutive year buyers. For example, I have a table like this: Order_year, Contact 2015, 123 2014, 123 2013, 123 2011, 123 2010, 123 2015, 234 2014, ...
2
votes
3answers
49 views

What schema for different relation from two tables to another?

There are three tables instructors, meeting_points and bookings. Here are the relation I want: 1 instructor has 0, 1 or n meeting_points 1 booking has 1 meeting_point 1 meeting_point can be linked ...
0
votes
0answers
12 views

Sybase: Delete foreign key IF exists fails

I've a database, on which we will have to delete of tables/foreign keys/view. We did deleted all the required element in PowerDesigner, then we did the "Apply model change to the database". We ...
1
vote
2answers
38 views

Looking for application which will provide to determine project database growth and cost per day or month

I am using SQL Server 2008 for product development Currently application is live with 20 users now if I want to check how my database is growing and how much it will grow in month or year projection ...
0
votes
0answers
14 views

Passing DataTable using SqlBulkCopy

Should I convert the DataType of DataColumns in to pass DataTable using SqlBulkCopy? This are the fields in my sql server database
0
votes
0answers
70 views

Need your help in query tuning

I read ​one article which shows how to use different aggregations effectively. http://sqlblog.com/blogs/paul_white/archive/2011/12/04/is-distinct-aggregation-still-considered-harmful.aspx I am ...
2
votes
1answer
23 views

Querying on multiple joined rows

I have a table called visits that is structured like so: +----+--------------+-------------+ | id | name | visitor_id | |----+--------------+-------------+ | 1 | event1 | 1 ...
1
vote
1answer
40 views

How to get the sum of filtered fields in SQL

How can I filtered values in SQL? When I execute this query, I'm getting the result below. SELECT Stock_TBL.StockID, Stock_TBL.ItemCode, Stock_TBL.ItemDescription, InvoiceItems_TBL.StoreName, ...