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

learn more… | top users | synonyms (1)

1
vote
0answers
6 views

how to use CASE statment in where clause in db2

I am using CASE statement in where clause like this- SELECT * FROM ASPECT.WR_AM_ADT_SUMM INNER JOIN ASPECT.WR_AM_DLR_DTL ON ...
-3
votes
0answers
20 views

I want to write query as per business requirement [on hold]

Universe Addition for Historic Data: Expired Contact Company Associations with companies as defined in universe, provided the record has either Committee or Compensation info, and belongs to Company ...
2
votes
1answer
29 views

Increase date by 1

I have a query that fetch whole year record and sums up the count.The query is as follows select count(*) as t, m.machine1 from sap_prod_data s left join sap_machine_speed m on s.mch_desc = ...
0
votes
1answer
30 views

Microsoft SQL Server Vs Oracle [on hold]

I'm working in SQL Server as database administrator/Developer, and currently I was thinking about oracle. Many people said that it is a future and we will have more oracle databases then sql server. ...
0
votes
0answers
9 views

Optimize Query - PostgreSQL 9.2

This is related to my previous Question: slow-query-optimize-postgresql The new Query is good, the missing piece is that the quantity & cost selectors are interchangeable (in code) with: if ...
0
votes
1answer
7 views

Access IFf Query

I'm new and just starting out at creating databases so I apologise if noob question. What I am trying to do is update my Staff table to show that "Sarah Avon" has married and her new last name is ...
0
votes
0answers
4 views

Forcing OBIEE to Act Like Excel… If, Then, Else Evaluates ONCE

I get duplicates that I do not want using the following expression with the subsequent data: Case When Locate('Stuffed',"Journals"."Journal Text") > 0 THEN 'Stuffed' When ...
3
votes
0answers
53 views

Sort operation sql server 2012

I am trying to optimize a query and the sort operation(91% cost) is the costliest operation.Any help will be appreciated. Query is : SELECT TOP 1 ArchiveType ,CONVERT(NVARCHAR(30), A.StartTime, 20) ...
2
votes
2answers
30 views

Generate a sequence of timestamps but skip given periods

I have a table things_to_do in PostgreSQL. For example: thing_id --------- 1 2 3 4 5 6 And I want to add a timestamp to every row: SELECT thing_id, '2016-02-10 19:57:00'::timestamp ...
0
votes
0answers
10 views

How to properly implement a relationship between a table with an array of foreign keys and the foreign table? [duplicate]

I'm not entirely sure how to implement this kind of relationship correctly. As an example, assume that we have: CREATE TABLE menu_item ( mi_name TEXT PRIMARY KEY, mi_ingredients TEXT[] ); ...
0
votes
2answers
15 views

Different where clause based on SSRS parameter

I have an SSRS report where a parameter can take 3 values. The select query is the same in all cases but the where clause needs to check different date fields based on the parameter value. Is this ...
4
votes
4answers
166 views

Question about 'mysql error 1064'

ALTER TABLE sample62 CHANGE newcol c; This code makes me mad. I just followed the book I had. Program said You have an error in your SQL syntax; check the manual that corresponds to your ...
0
votes
1answer
37 views

Cannot create user using administrator credentials in Oracle

I am trying to get some hands-on experience with ORACLE and I installed Oracle Database 11g Express Edition on my PC at home. I logged into the 'Application Express' by entering TEST in the Workspace ...
1
vote
1answer
40 views

How to select all rows from column including two specific numbers within a set of digits, but not in beginning or end?

I'm attempting to retrieve all rows that include two specific characters within a set of characters corresponding to the attributable column of data. However, the specified characters can't be ...
0
votes
1answer
61 views

How to optimize database for specific queries?

Hello I have built this queries thanks answers to my questions: How to get data from three different tables and How to show rows with 0 without any records in database But now I have performance ...
-1
votes
0answers
15 views

SQL Stored Procedure how to split column [on hold]

ALTER PROCEDURE [dbo].[MBResult] -- Add the parameters for the stored procedure here AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. ...
-4
votes
1answer
28 views

sql INSERT QUERY [on hold]

i want to write a query for this. I want to select funds from table1 and insert them into table2 in their respective hrchy no . as shown in pic
-1
votes
0answers
19 views

Writing SQL query for scenario [on hold]

I am trying to develope a shopping application. I need to write a query for the following table structures : enter image description here GRPMT : This contains the master group of Items(like ...
0
votes
0answers
30 views

Transaction Identifier - possible with MySQL?

I have quite complex code, which at the beginning starts transaction. After that several user queries are performed (more or less without my control) and at the end the transaction is committed if ...
1
vote
0answers
33 views

Change login name for all objects on server

Example, I have a create a windows login DOMAIN\GROUP01, and mapped that login to a database DATABASE01 with lets say DB_OWNER permissions I want to change the login name, I went into Active ...
1
vote
1answer
72 views

SQL Query on partitioning does not run [duplicate]

When I run the following SQL command select payee_id, start_dt, row_number() over(partition by payee_id order by start_dt) as rn from xxx where rn = 1 I got an error : error Invalid ...
2
votes
2answers
88 views

Ordering groups/partition windows by other column values

I have a sample from a database I'm using in SQL server 2014 you can use here http://sqlfiddle.com/#!6/0d98e/1 It looks like this ...
-2
votes
0answers
19 views

My login page is returning Unknown column 'sitlanic' in 'where clause'

My login page is returning: Unknown column 'sitlanic' in 'where clause' $uname = $_POST['name']; $pass=$_POST['b']; $sql="select*from names where username=$uname and password=$pass"; ...
0
votes
0answers
43 views

create table in a different schema

I am trying to create a table on a different schema without using "create any table" privilege. I have an application user/schema. TABLESPACE_NAME USEDMB MAXMB ...
0
votes
1answer
31 views

MySQL - Many to Many Join. Left Join already Present

I am building a Attendance System for a Client and have become a tad stuck with JOIN's. I already have a left JOIN running, and want to add a JOIN on a many-to-many relationship but can't get my head ...
1
vote
2answers
57 views

SQL Server Concurrency Issue [on hold]

We have a SQL server concurrency issue we are facing and would like some ideas on how to solve it. There are several procedures we have written the contain INSERT/UPDATE statements on tables in a Set ...
1
vote
1answer
52 views

understanding ORA-01792 maximum number of columns in a table or view is 1000

We've recently migrated a server from Oracle 11 to Oracle 12c and ran into a few annoying issues. One of them is that a few a reports give the following error: ORA-01792: maximum number of columns ...
2
votes
0answers
62 views
+50

How to Replicate data between a hosted database and a local database

I have a Cloud hosted Database, maintained by a different company. Here is my scenario: Cloud Hosted Database SQL Server 2012 - Need to connect through a VPN. We setup a local Server with with ...
0
votes
2answers
40 views

Query that finds the oldest driver

Given two tables: driver=(d_id,name,gender,birthday,address,country) event_list=(o_id,d_id,odate,oplace) The event list table represent the driving violations of the driver , o_id is the violation ...
3
votes
1answer
79 views

How to show rows with 0 without any records in database

I have a lot of record in my database and for data analysis, I need to show count of records for each day including days when I do not have any record, so result is 0. For example I have these ...
0
votes
1answer
26 views

How to get average of views before clicking on advertisement?

I've got two tables containing information about viewing and clicking on advertisement by each user: Clicks: userID Action Time 123 c 2016-01-08 01:57:00 123 c 2016-01-11 ...
0
votes
0answers
11 views

Trouble With Basic Query Searching [migrated]

Not sure if the this is the right place to ask but i have a question with beginner sql. I have the table dept and emp which include: SQL> desc dept; Name ...
0
votes
1answer
56 views

Oracle SQL: Outer Join Not Working As Expected

I am joining two tables, T_ADMSTU_PROG_ENROLL (renamed prog_enroll) and T_ADMGRAD_STUDENT (renamed grad). I would expect the result to have the following columns: TERM_CODE, STU_INST_UID, MAJOR_DESC, ...
0
votes
0answers
25 views

transpose rows into colunms based on date grouping

I have a table with rows as such Number Date Number2 16 2016-02-03 34 9 2016-02-03 34 30 2016-02-03 34 7 2016-02-03 34 47 2016-02-03 34 1 2016-02-03 34 ...
3
votes
2answers
64 views

Creating calculated column

I want to create a rating weight and I need do calculate AVG, then find COUNT and multiply both to get weight. I have something like that: SELECT post_id, COUNT(CASE WHEN vote > 0 THEN vote ELSE ...
1
vote
1answer
28 views

Show only duplicate values

How to select rows with duplicate values (non-distinct rows) and summarize with a count of the number of duplicate values in order of the most frequent duplicates? Given a table of: person_ name_ ...
0
votes
0answers
25 views

Join query not working [closed]

select distinct concat(ed.first_name,'',ed.middile_name,'',ed.last_name) empname, emp_fkey, au.* from emp_details ed INNER join emp_ctc_upload au on (ed.emp_pkey = ...
-1
votes
0answers
26 views

windows 10 home, 64 bit… trouble running a certain software requiring 2k8r2, would like to run these ideas by you [closed]

I need to run a programming software that requires 2008r2, I cant finish installing the software because it wants to install its own instance of 2k8r2. Can I install sql first then run the software? ...
0
votes
1answer
20 views

MS Access Run Multiple Queries

I have eight 'append' queries in MS Access 2010 that I want to be able to run. Each query also needs to take one parameter (a project number). I want to run all eight, entering the parameter only ...
1
vote
1answer
30 views

How to check value when i have a list of elements separated by comma in a column?

I am looking to return a value in a database. Table named TIPOLOGY is structured like this: Name Owner ID Office Type LIST_OF_VALUES Jones Lasi 1 12345 TKT AUD,PAX,CCF ...
1
vote
2answers
149 views

novice-design: Are FOREIGN KEYs always necessary? Joins on columns which are not PK

I've been wondering if following approach is bad or really very bad:). Question#1: can we use indicator_id to combine data from indicator_values and indicator_details tables (without using FOREIGN ...
0
votes
0answers
34 views

Deleting a Row in Table- Best way to also delete all rows it affects? [closed]

I have created a very simple SQL script (see below) that deletes rows in my table if a column name is a certain value. DELETE FROM table_name WHERE some_column=some_value; However, this table ...
0
votes
0answers
24 views

Next date to be displayed [closed]

train depature and arival arv dep day 13:40 pm day 1 20:45 pm 23:20 pm day 1 02:20 am day 2 I need the output as (give input as ...
1
vote
2answers
97 views

Which data type should I use to store a 11 digit number [closed]

Which data type I should use to store an 11 digit number? It must store '0' as the first digit. For example, if I store 02421402015, it must show 02421402015. I tried using varchar and it shows ...
-1
votes
0answers
14 views

Discriminating rows where column start and/or end with dots

I have a table where rows are stored as follow: # id alias_desc state 1 3 Alison a 2 4 Alison. a 3 5 Alizon a 4 6 Alizon. a 5 7 Amada a 6 8 Amada. ...
6
votes
2answers
237 views

Add [Is Primary Key Column] to this query

I made this query, to list tables, its columns, data type and etc: select t.name as 'Table', c.name 'Column', ty.name 'Data_Type', c.max_length as 'Max_Lenght', ...
0
votes
0answers
42 views

What is the best ways to filter data on the fly

We are implementing a new plan for ETL database, but we do not want to store the intermediate table on our local sql server (only want those records that we need). any body know the best ways to do ...
0
votes
0answers
35 views

Headers and footers for Crystal Reports [closed]

I have three tables: Employee [EMPNAME, EMPID] ProductList [ProductName, ProductCode] Orders [EMPNAME, ProductCode, ProductName, DeliveryDate, OrderDate, TOTAMT] I am trying to ...
2
votes
0answers
34 views

Design a many-to-many table for scale

I am thinking about scaling issues with many-to-many join tables. I have a constructed example as following: Many users have many wishlists. On every wishlist are many items. If I scale this ...
0
votes
2answers
25 views

Combine multiple row's records in one row with MS Access Query?

I have a table (name- tbl2) with 21 column but I want to combine multiple rows records in a row by using a unique reference number as below: Table Field and Records Type Expected Result: Please ...