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
10 views

I have a query which does not return result with the desired alias names of columns in PostgreSQL

The following is my query which does not return result with the desired alias column names: with d as (select distinct emp.ahrims_id, rank.name as rank from hr_employee as emp, ana_rank as rank, ...
-1
votes
0answers
7 views

Disk Space issue

I am facing one problem regarding Disk Space issue. One Disk size is 249 GB,it contains only .mdf files. Now the Disk utilization is 84%. How can i reduce Disk utilization less than 80%.
0
votes
1answer
10 views

Slow query / Indexes creation (PostgreSQL 9.2)

I have the following Query: explain analyze SELECT split_part(full_path, '/', 4)::INT AS account_id, split_part(full_path, '/', 6)::INT AS note_id, split_part(full_path, '/', 9)::TEXT ...
0
votes
1answer
26 views

Get dates between two months

Can I know why am I getting weird output in my SQL statement whereby my table has two dates of the month May but it only appears for one month, the same things I test for dates range it is working. ...
0
votes
0answers
4 views

Python and SQL exception handling when internet cuts out

I have a python temperature monitoring program that runs every 30 seconds on my raspberry pi, and uploads the data to an SQL server. I am using try: and except: however this doesn't handle if the ...
0
votes
0answers
25 views

what does “\” symbol mean?

I am new to database learning and came across this \ symbol. I googled but couldn't find what it meant. It was used in the context Q = R\S. (The = sign here is equivalent to)
0
votes
2answers
9 views

postgresql - how to find and extract text from a description column

I'm trying to create a new table using data from an existing. I have the following structure: Table "public.def" Column | Type ...
1
vote
1answer
10 views

Is DISTINCTROW in MS-Access the same as selecting all the fields and doing a group by on all of them?

I was looking though some queries in MS Access, and I found an SQL keyword I was unfamilar with called DISTINCTROW, from what I can tell, it's the same as an SQL GROUP BY which includes all the ...
5
votes
3answers
153 views

Selecting one row from each group based on a Varchar field

Given a table Avenger whose data looks like this: id Avenger Type Power 1 Captain America foo 2 2 Captain America bar 3 3 Me foo 5 4 You ...
1
vote
1answer
21 views

Using a join operation with conditionals

I have two tables that I'm working with in my database. I am using SQL Server 2014. One is 'versions', that contains version_id, version_number, start_date, end_date and server_id. The other is ...
1
vote
2answers
24 views

Using Variables to contain column names for SQL Server Merge statemtns

I'm trying to automate the column list grab for a merge job, and running into a bit of a head scratcher. I don't want to have to manually type out all of the column names, and thought I may be able to ...
0
votes
1answer
30 views

Altering column data SQL

I have a set of car data, one of the columns represents the registration year. I want to change this column to age. As the data is from 2010 I assume that the following statement should calculate the ...
0
votes
1answer
30 views

List of queries run

I'm looking for a DMV query for SQL Server 2008 R2 which shows me all queries (full history) run by a specific user. I have this code for now: SELECT * FROM sys.dm_exec_query_stats qs CROSS APPLY ...
1
vote
1answer
20 views

Display dates not in ascending for To_Char

can i know why and how i can solve the problem whereby if i use To_Char it does not sort the date in ascending. Below is my code select distinct To_Char (attendance_Date, 'dd/mm/yyyy') from ...
1
vote
1answer
25 views

Using SQLCMD with Variables

Im trying to do some general script that i can use to run the same INSERT/UPDATE or DELETE statements on different site databases. This was my first attempt which works just fine, but i have to copy ...
0
votes
1answer
19 views

Get data from previous years dynamically

I have a table with columns id, fname, date_field. date_field's records are: 2011-03-01 2012-03-01 2013-03-01 2014-03-01 2015-03-01 2016-03-01 I want the data for the past 2 years for each record ...
1
vote
1answer
18 views

index creation - Slow Query - PostgreSQL 9.2

I've got the following query: SELECT * FROM ( SELECT split_part(full_path, '/', 4)::INT AS account_id, split_part(full_path, '/', 6)::INT AS note_id, split_part(full_path, '/', 9)::TEXT ...
1
vote
1answer
30 views

Capitalize only the first letter of a name

I have a table Vendors that contains a column VendorContactFname, which is written in lowercase. I want to capitalize only its first letter. I am thinking of concatenating an Upper on the first ...
2
votes
1answer
22 views

Relating 2 tables with possible wildcards?

I am having trouble getting the desired results when trying to relate the following tables. NULL in the following table essentially means that if it is not an exact match with another row then choose ...
1
vote
1answer
27 views

Duplicate key value violates a unique constraint

I've been looking at other posts. It seems many people have had this problem, but I'm somewhat new to Postgres and tried other solutions with no luck. I have ny_stations table: CREATE TABLE ...
1
vote
1answer
24 views

sql getting sum of calculated columns

How can I get the sum of TotalAmount as single value for example Product Name UnitPrice Quantity Discount% Amount SharingCost% ShippingCost CustomsCost TotalAmount pro1 ...
0
votes
1answer
8 views

A different number of AFTER INSERT trigger alarms in SQLite and SQL Server

I have trigger CREATE TRIGGER [Foo] AFTER INSERT ON [Bar] BEGIN UPDATE Log SET count = count + 1; END When i execute query insert into Bar (ColumnName) values ('SomeValue1'), ('SomeValue2'), ...
1
vote
1answer
23 views

Tricky condition for PostgreSQL UPDATE query

I need help with a PostgreSQL query. I have a Django app + pg backend, where users post interesting URLs (or links) and can then comment under such links (called replies). There are two pg tables to ...
0
votes
2answers
23 views

Using Select Statement to get column name and table name from the same table

I have a table containing 2 Columns : Column1 (table_name) and column2 (column_name) like this : (Column 1) (Column 2) |Column_Name | Table_Name | -------------|------------| ...
1
vote
1answer
22 views

Select rows until a condition is met

Given: CREATE TABLE T ( x int not null primary key , y int not null ); INSERT T(x,y) VALUES (1, 0) ,(2, 0) ,(3, 0) ,(4, 0) ,(5, 3) ,(6, 0) ,(7, 4) ,(8, 0) ,(9, 0); The ...
-1
votes
0answers
14 views

PL/pgSQL trigger function syntax error at END; [on hold]

I'm writing a simple trigger function, as seen below. For context, it's meant to enforce uniqueness of a key across multiple tables. It will be made more generic once I've got it working. CREATE OR ...
0
votes
1answer
23 views

Display the the result of a substraction in a MySQL query (1 table)

I've made a table that looks like this: stop (table name) -cityName {PK} -schedule {PK} -price -routeNo Basicly the customer wants to know what's the cost difference between 2 different stops by ...
-1
votes
0answers
20 views

Functional Dependency Diagram From the Result of a Query? [on hold]

I was wondering if someone could explain to me how this works. I understand the concept of functional dependency diagrams i.e being given a set of attributes and split the tables using the diagram to ...
2
votes
2answers
46 views

Select rows where smaller row does not exist

Consider the following table data: ID NAME 1 Kshitiz 2 Aman 5 Aakash 6 Manjeet Here there are records missing between 2 and 5. What query can I use to select row 5 in this table?
0
votes
1answer
16 views

On the fly MySQL balance

Please excuse my English translation that makes by Google Translate I need to solve the following in a MySQL query without php or another language: In the “A” column I have a string value, in ...
0
votes
1answer
13 views

SQL 2012 Availability Group issue - The core cluster resources do not move when we initiate AG fail-over

I have a Windows 2012R2 cluster with two nodes and a File Share quorum. I am running SQL 2012 SP2 and I have configured a test AG with a dummy database. When I fail-over the AG, the Availability ...
0
votes
1answer
13 views

(SQL) User tables are separated into two sections

Using SQL Plus, I create 13 tables via an .sql file, each containing primary and foreign keys. When I execute "select table_name from user_tables;" they are displayed in this partitioned fashion. ...
-1
votes
3answers
44 views

how to find the last date from the week number as input

I need to find the last date of week when i pass year and week number as input in my stored procedure. week starts on monday and last day of week will be friday. Database - IBM db2 9.7 platform - ...
-1
votes
1answer
18 views

Data Quality Service (DQS) and Master Data Services (MDS) [on hold]

Best practice question. Is anyone using one of these in production? Can you share your experience and the business need you were solving with it? I am learning about them and do not really see the ...
0
votes
1answer
20 views

List objects in SQL file

We are trying to migrate a database from SQL 2014 to Azure SQL. In SSMS, you can right click on the database and then on a task to "Deploy Database to Windows Azure SQL Database..". This task ...
2
votes
1answer
38 views

Search for X at the beginning of a line within a multi-line string

On SQL Server (2008), I have a column which is varchar(max). I want to query for all rows where the blurb contains a lettered list: Some sentence is here a. foo b. bar c. baz Some more text later ...
0
votes
1answer
18 views

Dumping and restoring tables in PostgreSQL - ERROR: extra data after last expected column

I am trying to dump and restore multiple tables from a database on one server, to a different database on another server. Both are running Postgres 9.4 on linux. The command for the backup was: $ ...
0
votes
1answer
15 views

VMware vFabric Data Director [on hold]

https://www.brentozar.com/archive/2013/04/cloud-alternatives-to-microsoft-sql-server/ I liked the idea of VMware vFabric Data Director so I can host data in own cloud / data centre. It seems this ...
3
votes
1answer
58 views

Amazing improvement of script execution speed when split - not understood

I have an ETL job that merges data into about 20 columns of a fact table, all integer non-null (default 0) columns. There are 8 merge statements to completely update all the columns and they involve ...
0
votes
1answer
19 views

Result consisted of more than one row in procedure

i confused with this i try not using cursor and same get error so i back using cursor but before this day my query success and can generate but this get error please help me i already look other ...
0
votes
0answers
21 views

How to use a cross reference table for different features of a product in different versions?

I am creating a database for one of my classes. I am using SQL Server 2014. I am designing a database that monitors the source control of development of different products. This company has different ...
1
vote
2answers
42 views

Join two tables using pivot combining two columns in one table

I have two tables in this format: Job_Skill ID_Skill Min_Job Idea_Job Max_Job ===================================== 1 0 0 1 2 0 1 1 7 1 ...
6
votes
3answers
99 views

Query wont compile/run

I have a query that won't run on the production server but it runs on the test server. It seems like the query plan won't compile or its compiling a very bad query plan. I have updated all statistics ...
0
votes
0answers
15 views

transfer the new posts on local to host [on hold]

I want instead of creating new posts on webhost, firstly created on localhost and then I transferred to the webhost; this is not problem for me till here, but After transferring a number of posts, if ...
0
votes
1answer
26 views

Script to Delete Tables With A Prefix

I am running SQL Serve 2008 and we have a few test tables that were obviously used for testing. The prefix of the tables are Test_, my question is, will this script delete all tables with the prefix ...
1
vote
1answer
36 views

Use a scalar hashing function in a computed column - non-deterministic?

I have a scalar function select [dbo].[fn_get_hash_fields] ('blah','dbo') to which is passed a table and a schema and which returns an expression representing a concatenation of all column values ...
2
votes
1answer
61 views

Why is Include Actual Execution Plan not included in @@Rowcount when it produces a row count?

While updating a column in a table the last day I was shown a new technique by our Senior DBA to reduce reads and contention. The pseudo-code is WHILE [always true condition] BEGIN UPDATE ...
0
votes
0answers
61 views

Trying to find a MIN() workaround for an indexed view

I'm trying to speed up a SQL Server query using indexed views and I have one slow element which I think is due to the use of GUIDs for the particular comparison column. The GUID can be mapped to an ID ...
0
votes
0answers
30 views

Convert table values into column header without PIVOT [number of column values is dynamic] - Oracle 10g [duplicate]

I have a table in the following format ID NUM P_VAL Q_VAL ---------------------------------------- 445120000 00 101 25 445120000 10 103 25 445120002 00 ...
0
votes
0answers
14 views

cannot call json_array_elements on a scalar [on hold]

I have JSON values like this: [{"lang_id":179,"language_id":26,"phy_id":82,"language":"Duch"}, {"lang_id":177,"language_id":16,"phy_id":82,"language":"ENGLISH"}, ...