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)

3
votes
0answers
13 views

How can I get a hierarchial json from the same table in postgres

I already posted it here but it was wrong place and the answer is for wrong version: http://stackoverflow.com/questions/31264334/how-can-i-get-a-hierarchial-json-from-the-same-table-in-postgres ...
0
votes
2answers
27 views

How to optimize a large join to create a WHERE IN

The following sqlite database query takes about 40 seconds on my Core i7. SELECT t.a FROM titles t WHERE t.a IN ( SELECT e.id FROM erpubtbl e JOIN abstract_mesh am ON am.pmid = e.pmid ...
0
votes
1answer
24 views

How to print to console in SQL?

I'm using PostgreSQL And I want to print a message to the console. If I use plpythonu I use plpy.notice If I use plpgsql I use raise notice but how do I print when the function is pure SQL? using ...
2
votes
1answer
27 views

Pivots giving too many results

I'm trying to learn how this pivot thing works. I don't think I'm understanding it quite right. I just want to do a simple count for a bunch of item types that have some statuses. The table I'm ...
0
votes
0answers
1 view

Last accessed timestamp of a Netezza table?

Does anyone know of a query that gives me details on the last time a Netezza table was accessed for any of the operations (select, insert or update) ? Thanks
1
vote
2answers
48 views

SQL - Select Rows in a Certain Order

I'm new here - if I missed anything in the question please let me know. I'm trying to build a people directory like LinkedIn has: http://www.linkedin.com/directory/people-a I don't want to fetch ...
-3
votes
1answer
44 views

SQL Server questions (for masters) [on hold]

How to rename sa to new_sa in SQL Server 2000? How to do and what is the impact SA rename impact in SQL Server 2005, 2008, 2008R2, 2012, 2014, Express Edition How to recreate sa login if deleted How ...
1
vote
1answer
19 views

Update reps table with right values in a trigger after insert on userterritory

I two DBs veeva and pdone as shown below in the pics As you can see veeva is simple and hasn't no constraints which relies on duplicate and wrong values. The problem happen exactly on ...
1
vote
1answer
29 views

how to avoid duplicate record with certain conditon

Heading ##I have a table with data like below +----+--------+-----------+----------------+ | id | name | testfield | status | +----+--------+-----------+----------------+ | 1 | raju | ...
1
vote
1answer
20 views

Weed out certain rows where timestamp is within interval

Given a table structure: create table contacts ( contact_id int(8) not null auto increment, #primary key pid int(8) not null, #personal id contakt_time datetime, ...
0
votes
0answers
14 views

Hibernate query results are missing rows with empty value in filter columns

I have two tables with foreign key references: Comm TABLE: +----+------------+ | ID | NAME | +----+------------+ | 1 | comm name1 | | 2 | comm name2 | | 3 | comm name3 | +----+------------+ ...
0
votes
1answer
26 views

select row where a couple of column values is different [on hold]

I have a table A with thoses columns : date, ip, created_by. I would like to display date, ip and created by of rows where for one ip it exists different created_by. Thank you I explain more : ...
1
vote
2answers
26 views

sql join with laravel query builder

I have a transactions table with the following field: Transactions ID | amount | branch_id | supplier_id 1 | 1,200 | 2 | 1 Subsidiary ID | Name | Type 1 | supplier1 | 0 2 | ...
2
votes
1answer
18 views

How to do housekeep the database in sql server 2008 by specific date range?

I have database with around 160 GB size. The database contains the data is from 2013 to until today, there are 180 tables, I want to remove the records in specific date range like 2013 to 2014 in all ...
2
votes
0answers
13 views

How do I keep a postgres table up to date using instagrams api?

I want to update a table in postgres with the response I get from the instagram api. I saved the response as a json file and imported it using navicat but when I saved the import job in navicat it ...
1
vote
0answers
21 views

Complicated MySQL table reorder

I should do really complicated tables reorder. ****The main table looks like:**** id - some data 1 - ... 2 - ... 3 - ... 6 - ... 9 - ... 12 - ... As you can see, there are "empty" IDs (no 4, 5 ...
-3
votes
0answers
8 views

a phpMyAdmon database question [on hold]

I have two tables in database of phpMyadmin. One table is symptoms table, and 2nd is diseases table. The symptoms table has two columns: smpid and symptom The diseases table have three columns: ...
4
votes
0answers
43 views

Is this a sane model for a network provisioning system?

I'm sketching out a model for a network setup, where I have the following conditions: 1. There are multiple nodes which contains a number of switches each. 2. Each switch has multiple services, which ...
3
votes
1answer
22 views

Single table or multiple table design when records have a clear distinction but are queried together?

Let's say I have the following types of recurring data (all types periodically come in). Post (Title, Summary, Text, Timestamp) Image (URL, Caption, Timestamp) Event (StartDate, EndDate, Title, ...
3
votes
1answer
28 views

Importing via sqlcmd errors out

PS C:\Users\administrator.INTERNAL\Desktop> sqlcmd -S SQLMAIN\MSSQLSERVER -i rdmdb.sql Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : SQL Server Network Interfaces: Connection string is ...
4
votes
1answer
38 views

Select a count with some conditions

Using Postgres 9.4, I have a table page_views which has a page column. I'd like to select all the distinct pages and have a count before them and sort them descending. I'd also like to have a minimum ...
1
vote
1answer
18 views

Trigger is failing with no errors at all, why?

I need to UPDATE territory_id column at pdone.reps table by using and filtering results from veeva_new.userterritory so based on the answer I got here I am trying to build my own and this is how it ...
3
votes
1answer
23 views

Information about a column and the data it holds?

I'm working with a table that has 3 different dates associated with each item in the table. I don't understand what each time is so I want to know if there's a standard place that the person who made ...
3
votes
3answers
37 views

How to select a row based on the maximum value of a column, when ties are expected

SUBSCRIBER DATE TIME VALUE aaa 23-04-2015 04:04:07 10 aab 23-04-2015 12:04:32 5 bbb 23-04-2015 01:04:05 20 bbb 23-04-2015 ...
1
vote
1answer
59 views

My SQL Server table identity is incrementing way too fast

I have a table with pretty basic design: 1 primary key (id), 1 unique column (filename) (the filename of the file I am tracking) The primary key is an identity column (bigint) (I had to make it ...
-6
votes
0answers
23 views

How to join more than one table [on hold]

I'm stuck with one SQL query, the result as the image below : Could you help me to solve this problem? I already tried but the result is repeatly. And I don't know why? I followed the link How to ...
1
vote
1answer
40 views

Update records from one table to another in different databases where condition is accomplish

I have two tables stored in two differents DBs and I need to perform some sync between both tables based on lastmodifieddate and lastSyncAt. Let's call them as db1 and db2. This is the DDL schema for ...
3
votes
1answer
38 views

How to get the difference in days between 2 timestamps in PostgreSQL

I have a table named accounts. I am interested in retrieving those accounts whose status has not been updated since more than 10 days. I thought about this query and it seemed to work but I am not ...
3
votes
3answers
65 views

Insert data between 30 minute time intervals

I want to divided my to my time interval depending to the start time and end time. To explain it further, let me have this example. I have this table: User Elapsed Time Start Time ...
-1
votes
0answers
37 views

How to execute stored procedure from other database?

I have 2 databases. Example: db1 and db2. And db1 has a stored procedure sp1 with an input parameter. db2 has a stored procedure sp2. I am trying to execute sp1 in sp2. I tried below: I know it ...
2
votes
0answers
17 views

Sum of points and rank according to points with join three tables [duplicate]

I am creating a game where I am calculating the user points on the basis of user activities. Everything working fine I got the sum of points and on the basis of points I calculated the rank. I have ...
2
votes
3answers
60 views

Sum of points and rank according to points

I am creating a game where I am calculating the user points on the basis of user activities. Everything is working fine - I got the sum of points and on the basis of points I calculated the rank. I ...
1
vote
1answer
29 views

default constraint issue

I have a table say tempTable with one column having a default constraint ALTER TABLE [dbo].[TempTable] ADD CONSTRAINT [DF_TempTable_Version] DEFAULT ((1)) FOR [Version] Version decimal (18,1) ...
6
votes
1answer
39 views

How can I combine two event tables into a single timeline, in PostgreSQL?

Given two tables: CREATE TABLE foo (ts timestamp, foo text); CREATE TABLE bar (ts timestamp, bar text); I wish to write a query that returns values for ts, foo, and bar that represents a unified ...
-1
votes
2answers
39 views

Creating Stored Procedure with TableName as parameter

I am attempting to create a stored procedure where a table name is passed as a parameter, as well as updating contents of the table. Here is my code I have so far. ...
0
votes
1answer
23 views

Formatting a DATE type in an Oracle database to only accept MMDD

Is there a way to limit the inputs into a DATE type in an Oracle database to only accept inputs formatted with only the day and month (not including the year)?
-1
votes
0answers
5 views

SendObject Command

So I have sorted out alot of the problems with query etc. Is it possible to have a DoCommand Send object to send a report to the emails in the query. I need the report to be the one referenced in the ...
1
vote
1answer
33 views

Alter of stored procedure and execution performance

I would like to understand how an alter of a stored procedure without modifications can impact performance. I had a situation where a production environment had its database schema updated and a ...
0
votes
0answers
7 views

ALTER SESSION from a Control File

I am using a Control File to import data from a CSV file into a table, using sqlldr to import the data, where a large number of fields are numeric values with integer and decimal part separated by ...
0
votes
0answers
21 views

Getting TEXT data from postgres throught linked server to MSSQL

I'm using MSSQL 2008 R2 with linked server to postgres 9.4. My problem is: when I select column with data type text it shows me only XXX first chars and adds (...) on the end. select description from ...
-2
votes
1answer
41 views

Recursive cte addition in SQL

I need to add the total value to the parent nodes.(totaling the total value to base to top levels). 118 records are there and 1-8 levels. Root ACCCODE='00001' Root ACCPARENTCODE='0' Eg: adding ...
2
votes
1answer
33 views

table structure for events

Got a bit stuck, need a hand. I need to store events at the database, and events may happen at different location multiple locations at the same time so these are my tables CREATE TABLE ...
1
vote
2answers
26 views

Select data where column value exists in seperate rows for same reference id

This is on a MySQL database. Locations have services. What I want is to get all results where service_id is 2 AND 3, not OR so using IN is out I believe. Database ---------------------------- | ...
-5
votes
0answers
35 views

Why isn't my query returning the correct results? [closed]

I am trying to get information from several tables that I need in order to produce a report of all the stopped services on our critical servers. This query for some reason works if you switch the ...
-4
votes
0answers
19 views

SQLPLUS QUERY HELP [on hold]

Please help to create what might be a simple query for you; very tricky for me. Maybe a nested query?... or maybe a "For Loop". Thank you! Table name: WO_OPERATION Relevant Columns: ...
4
votes
1answer
102 views

Find rows where data resets

So I have a table tbl where I'm trying to pull data that increments at a variable rate. I need to identify when the data resets so I can make a cumulative value. Here's an example table: ID VAL ...
4
votes
2answers
129 views

Reseed identity column in all empty tables [duplicate]

I need to write a query that resets the identity on all tables that have an identity column and are empty.
0
votes
0answers
9 views

Why are some of my migrated tables showing “The given key was not present in the dictionary” in WebMatrix's interface?

I'm having an issue while using the SQL Server Migration tool to convert Access accdbs into SQL Server 2014 Express. I am converting the tables using SQL Server Migration Tool and I have a connection ...
-9
votes
1answer
54 views

Stored Procedure which INSERT, UPDATE, DELETE any table(for any table) where table name and its values are passed as parameter [closed]

Stored procedure which performed operations like inserting data to table, updating data, and deleting data of table where table name is passed by parameter. Parameters of stored procedure: table name ...
5
votes
3answers
159 views

Postgres is performing sequential scan instead of index scan

I have a table with about 10 million rows in it and an index on a date field. When I try and extract the unique values of the indexed field Postgres runs a sequential scan even though the result set ...