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
1answer
38 views

Sql Rank for records contain multiple combinations

I am trying to filter the records which contains multiple combinations and removing the records which contains a single combination. Database DB2 Query Used: select * from (select ...
0
votes
0answers
13 views

DB replication, each db their own distributor or use a single distributor?

this may be a simple question for most but I am a bit confused and could use guidance, I am not a DBA, however I need to present out case for servers to our DBA's I am looking to set up replication ...
1
vote
4answers
215 views

NVARCHAR column as PRIMARY KEY or as UNIQUE column

I'm developing a SQL Server 2012 database and I have a doubt about nvarchar columns as primary keys. I have this table: CREATE TABLE [dbo].[CODES] ( [ID_CODE] [bigint] IDENTITY(1,1) NOT NULL, ...
2
votes
0answers
49 views

Change Tracking across several Tables

I'm looking into providing DB level change tracking within my system. I need to be able to track changes at an entity level, rather than just individual tables. Right now, we have triggers on each of ...
0
votes
0answers
29 views

Deleting already duplicated Filestream Files

I have three FileStreams (FS1 on F drive, FS2 on H drive, FS3 on E drive) belonging to the same FileStream group of one particular database (DB) which is in Simple recovery mode in the SQL Server ...
2
votes
2answers
165 views

Database-agnostic stored procedure call passing array of name/value pairs

Background Looking to pass a set of name/value pairs into a stored procedure in a database-agnostic way, using JDBC. A database structure is defined as follows: CREATE TYPE array_parameters AS ( ...
1
vote
2answers
115 views

How to split url in sql server like this

Here is the url www.abc.com/a/b/c/d/e/f/g/h/i I want result like this www.abc.com/a/b/c/d/e/f/g/h/i www.abc.com/a/b/c/d/e/f/g/h www.abc.com/a/b/c/d/e/f/g www.abc.com/a/b/c/d/e/f ...
0
votes
1answer
47 views

Setting a column's default value by adding a constraint

I wrote this query: ALTER TABLE test2 add constraint setting_value33 default male FOR namee; But I get this error when running it: You have an error in your SQL syntax; check the manual that ...
0
votes
1answer
43 views

How do you use COLUMN_JSON with COLUMN_GET on dynamic columns in MariaDB?

When I do the following query; SELECT name, COLUMN_GET(attr, 'appearance' as char) as 'attributes' from items; I see the 2 columns including the blob data with the weird formatting. Is it ...
1
vote
1answer
39 views

Sql Insert into with duplicate key

Ok so, I'm still a beginner in databases. I have this code: $sql=" INSERT INTO complaints_members (password, complaint) VALUES ('$mypassword','$submit') ON DUPLICATE KEY UPDATE ...
0
votes
0answers
37 views

Why does the SQL Server 2012 SA account always show up with creation date of 4/8/2003?

Why does the SQL Server 2012 SA account always show up with creation date of 4/8/2003? I am not sure why this is happening and if this is something that needs to be resolved. I noticed that on ...
0
votes
1answer
27 views

Query performance with primary keys of different data types

Is there a significant difference in performance if i decide to use INT or BIGINT as data type of a primary key in a table? Of course if i use BIGINT the value will have twice it's size. But as the ...
0
votes
2answers
53 views

How to split a row in a result into mutliple rows

I have the following query: SELECT vs.MonthName AS Month, vs.Region, vs.Category, CAST (MIN (a.TotalAmount) AS money) AS ActualAmount, MIN (a.TotalCases) AS ...
0
votes
1answer
43 views

Nice query to get my friends

my table has this structure: User_ID | Followed_ID Example row: 33 | 36 Means that user 33 follows user 36. If exists a record like 36 | 33 then the two users are considered friends. ...
2
votes
1answer
45 views

Order by where conditions

SELECT * FROM table WHERE key REGEXP 'some long regular expression' OR key REGEXP 'some other long regular expression' ORDER BY key REGEXP 'some long regular expression' DESC, key REGEXP 'some other ...
1
vote
1answer
122 views

Can Execute trigger in SQL Server 2008 R2

I'm trying to create a simple trigger to update a table's column after it was inserted. But when I execute the trigger it produces an error: Cannot execute script. Additional information: Unable ...
1
vote
2answers
93 views

Optimizing a Postgres query with a large IN

This query gets a list of posts created by people you follow. You can follow an unlimited number of people, but most people follow < 1000 others. With this style of query, the obvious optimization ...
0
votes
0answers
47 views

How can I make a foreign key from a fragment of the primary key?

I have this table: CREATE TABLE Phones ( Brand VARCHAR(20), Model VARCHAR(20), PRIMARY KEY (Brand, Model) ); A mobile phone can't be uniquely identified just by its model (for example: HTC (One) or ...
0
votes
1answer
47 views

Convert an interaction matrix into a ternary relation

I have what I'm calling a sparse "interaction matrix" of data in MS Excel that I wish to convert into a "ternary relation" (table) in Access. The spreadsheet data are in this pattern: Name Act-1 ...
0
votes
1answer
71 views

Is there a reason my CTE with a basic subquery in the second stage of the CTE is failing?

Ok... anyone aid with this sorry...i've been playing with some of my works reports and i thought id found a way to mix two results into one when i came across a small issue... if i run my CTE code ...
1
vote
1answer
90 views

Modifying a non managed table partition

I ran across a partition that was initially setup (sql 2012) beginning of 2014 to break by month but wasn't updated for 2015. The main issue is that the last partition was setup as Jan 2015 so Feb ...
1
vote
1answer
42 views

SQL server compress backup for lower version databases

Recently our development team migrated couple of sql server 2000 Databases onto SQL2K8R2. Now we creating the backup strategy, and just had a doubt, that: 1) Compatibility level of those DB's still ...
2
votes
2answers
174 views

SELECT WHERE CASE

I have the following table (MySQL): -------------------------------------------------------- | id |product_id| store_id | stock_id | priority | ...
0
votes
4answers
36 views

ISNULL() OR Is NULL in UPDATE statement

I have to run UPDATE statement on live online database about 5 lac records so i want to know which statement are run faster Update Table set REC_ID = isnull(REC_ID,'') Update Table set REC_ID = '' ...
1
vote
2answers
61 views

DB backups for production to DR without creating jobs in prod

I had two servers(SQL 2005) A and B. B is Production server and A is DR. I want to take backups for B server databases from A server. We can not create any maintenance plans or jobs in B production ...
0
votes
0answers
83 views

count rows with same value and get column from other table

I'm trying to count product numbers for a period of time there are three tables. invoice (table) Column Column ------------------------------------------- |invoicenumber ...
0
votes
1answer
23 views

How to use a group by in inner join

I have Two tables Table 1 ID totalamount 100 1000 101 500 Table 2 ID Individualamount 100 500 100 300 100 100 101 ...
0
votes
1answer
33 views

HAVING ANY in Postgres

I'm looking for the right syntax to filter groups (i.e. groups of rows that have been GROUP BY'd) where at least one row fits a certain condition. For example if I wanted to select a group where at ...
1
vote
1answer
42 views

invalid memory alloc request size on simple query with array_agg on Postgres 9.3

Postgresql 9.3 - Debian 7 54gb RAM 8 cores (On google compute engine) I have a huge table called search_token (~50M rows) and I'm trying to execute a very simple query that is: select ...
0
votes
1answer
27 views

Insert where not already available for FK?

I'm looking for a simpler way to do this as I'm clearly thinking like a developer instead of a DBA. How would a DBA tackle this? I have a table with 3 column: PK, Name, FK. PK Name FK 1 ...
1
vote
0answers
20 views

Removing Orphan Pull merge replication subscriptions

I have a merge replication set where I have removed one of the pulled subscriptions. On the subscriber the subscription shows up after deletion. It will not go away. I tried the methods provided on ...
0
votes
1answer
1k views

Conversion failed when converting the nvarchar value '0.000000' to data type int

I have a code select CONVERT(NUMERIC, CASE ISNULL(FLEXFIELD4,'') WHEN '' THEN 0 ELSE FLEXFIELD4 END ) FROM DEIT_INDENT_DTL_INBOUND_RXL WHERE IND_INDENT_NO='NEE15SR000003' which is ...
1
vote
2answers
83 views

Count values from one table using two columns in another table

I have a problem. I have table_1 (col1, col2, value) and table_2 (col1, col2). I want to count values from table_1 but only the rows which exist in table_2. In both tables col1 and col2 are key (not ...
-1
votes
1answer
168 views

use variable as column name in where clause in sql

I want to use a variable as column name in my SQL query. Problem: I can not use dynamic SQL as the SQL query that I have is inside of a user defined inline table function. What are other possible ...
0
votes
0answers
47 views

Query gives not result

I have a quite simple table with different values. When I search a specific column no results are given. What could be the error? For example I search for an "id": db=# select * from table where id ...
1
vote
1answer
31 views

How to include a where clause in a query from another column

I have two tables: pointer_table(col_name varchar, col_val varchar, wh_clause varchar) value_table(col_1 varchar, col_2 varchar, value varchar) col_name in pointer_table denotes the column in ...
2
votes
1answer
41 views

SQL Maintenance Rebuild Fails

I am pretty new to SQL and I have this maintenance job that keeps failing and I am not sure how to troubleshoot this. I have troubleshot other job failures with google help to success but this one is ...
0
votes
1answer
30 views

Querying sums of grouped consecutive rows in PostgreSQL 9

I have data about people traveling in different countries like this: country | begintimestamp | distance Germany | 2015-01-01 00:00:00 | 100 Germany | 2015-01-01 01:12:13 | 30 France | ...
0
votes
1answer
79 views

Insert/Update SQL Server Stored Procedure

I have to insert or update into a table depending on a record. I am using a stored procedure to do this. I am very new to SQL Server and stored procedures. I tried to follow various articles and ...
2
votes
2answers
419 views

SQL Server: Frequent Login timeout expired in Linked server

I am using SQL Server 2012. I have scheduled a job to run every 1 hour, with 1 step calling 1 simple Stored Procedure. The Stored Procedure migrates around 1K data from production server to our local ...
0
votes
1answer
42 views

Convert string to number from xml at server side

I am having issues converting numbers stores as character (with . as decimal, sometimes are null) to number from xml on server side. Query is part of package. When I run the query below on my ...
0
votes
1answer
79 views

Comparing Column Value and Display the Differ Column

Supposed I have table temp A and table temp B, IF OBJECT_ID('tempdb..#A') IS NOT NULL BEGIN DROP TABLE #A END IF OBJECT_ID('tempdb..#B') IS NOT NULL BEGIN DROP TABLE #B END CREATE TABLE #A ( ID ...
2
votes
1answer
43 views

How to Create Aggregate function in SQL Server 2008

My requirement is to create concatenate function so I am trying to create Aggregate function as shown CREATE AGGREGATE [dbo].[Concatenate] (@value [NVARCHAR](MAX)) RETURNS[NVARCHAR](MAX) EXTERNAL ...
0
votes
1answer
26 views

Update statement with a function

I'm just curious. I was trying to optimize an update statement with a function Ex update circle set area = fnGetArea(radius) where ...<bunch of conditions> This update went 5-10mins and when ...
1
vote
2answers
106 views

Postgres multiple columns to json

I am running postgresql 9.3.4. I have a table with 3 fields: id name addr --- ---- ---- 1 n1 ad1 2 n2 ad2 ... I need to move the data to a new table with fields like: id data ...
0
votes
1answer
48 views

Query MST instead of UTC for timestamps

on SQL Server, i'm trying to query all of last months data based off of the time stamp, however, all those timestamps are in UTC and i need them to be in MST (the reason is mainly for the end dates) ...
2
votes
1answer
33 views

When to break large delete queries up?

I've got an auto generated join table (three columns, two of them keys to other tables), which was recently corrupted during an aborted migration. As a result there are around 1 million duplicate rows ...
2
votes
1answer
236 views

Foreign Key NULL vs Foreign Key to an empty string

This is a table for a catalog of medicines. Some have a pharmaceutical brand, others are generic (i.e. they will never have brand information) CREATE TABLE medicine ( id serial PRIMARY KEY, ...
1
vote
2answers
84 views

Calculating percentage from two tables

I have two tables: First one contains unique mentees under one mentor, so mentors can have more than one mentee in that table. Second one contains interactions of mentors with mentees on different ...
0
votes
1answer
49 views

Ranking not correct in sql server 2012 full text search

I am having a table like below: CREATE TABLE [dbo].[test_table]( [id] [int] IDENTITY(1,1) NOT NULL, [name] [varchar](50) NULL, [area] [varchar](50) NULL, [designation] [varchar](100) ...