sql

SQL Query - Get Sums from Two Different Levels of Hierarchy

A Project has multiple Tasks, which has multiple Assignments Projects (1-n) -> Tasks (1-n) -> Assignments A field on the Tasks table is Planned Hours. A field on the Assignments table is Assigned Hours. How do I get the Planned Hours and Assigned Hours for all Projects in a single query? ...

Autoincrement Primary key in Oracle database

Hi i would like to achieve something like CREATE TABLE RollingStock ( Id NUMBER IDENTITY(1,1), Name Varchar2(80) NOT NULL ); in Oracle how do i do it ? Thanks in advance ...

SQL Invalid Object Name 'AddressType'

I am getting the above error in my VS 2008 C# method when I try to invoke the SQL getColumnNames stored procedure from VS. This SP accepts one input parameter, the table name, and works successfully from SSMS. Currently I am selecting the AdventureWorks AddressType table for it to pull the column names from this table. I can see teh A...

Practical size limitations for RDBMS

I am working on a project that must store very large datasets and associated reference data. I have never come across a project that required tables quite this large. I have proved that at least one development environment cannot cope at the database tier with the processing required by the complex queries against views that the applicat...

Retrieve sequence of data from different columns.

Let's say I have a table containing following data: | id | t0 | t1 | t2 | ______________________ | 1 | 4 | 5 | 6 | | 2 | 3 | 5 | 2 | | 3 | 6 | 4 | 5 | | 4 | 4 | 5 | 9 | | 5 | 14 | 5 | 49 | I want to retrieve all the rows containing 4, 5, 6 (regardless the position of numbers in the tables), so row 1 & row 3 will be s...

how to get LIKE clause to work in ADO.NET and SQL Server

I am doing a really simple query in ASP.NET, but after I inserted the LIKE clause it stops working. Example: String sql = " SELECT * FROM Products WHERE ID = @MYID AND Name LIKE '%@MYNAME%' "; SqlCommand command = new SqlCommand(sql, cn); command.Parameters.AddWithValue("@MYID", M...

How to avoid the same calculations on column values over and over again in a select?

I sometimes write SELECTs on the form: SELECT a.col1 + b.col2 * c.col4 as calc_col1, a.col1 + b.col2 * c.col4 + xxx as calc_col1_PLUS_MORE FROM .... INNER JOIN ... ON a.col1 + b.col2 * c.col4 < d.some_threshold WHERE a.col1 + b.col2*c.col4 > 0 When the calculations get rather involved and used up to 3-5 times within the sa...

SHA1 Password returns as cleartext after DB query

Hi. I have a SHA1 password and PasswordSalt in my aspnet_Membership table. but, when I run a query from the server (a Sql Query), the reader reveals that the pass has returned as its cleartext equivalent. I am wondering if my web.config configuration is causing this? <membership defaultProvider="CustomMembershipProvider" ...

How to select a limited amount of rows for each foreign key?

Hi, I have this table: id feed_id ... Let's say that I have 500 rows and I want to select 3 entries for each feed_id? And 50 as total limit. How to write this SQL? ...

asp code for upload data

hello everyone i have this code for uploading an excel file and save the data into database.I m not able to write the code for database entry. someone please help <% if (Request("FileName") <> "") Then Dim objUpload, lngLoop Response.Write(server.MapPath(".")) If Request.TotalBytes > 0 Then Set objUpload = New vbsUpload For lngLoop ...

How to select DISTINCT rows without having the ORDER BY field selected

So I have two tables students (PK sID) and mentors (PK pID). This query SELECT s.pID FROM students s JOIN mentors m ON s.pID = m.pID WHERE m.tags LIKE '%a%' ORDER BY s.sID DESC; delivers this result pID ------------- 9 9 3 9 3 9 9 9 10 9 3 10 etc... I am trying to get a list of distinct mentor ID's with this ordering so I am looki...

Getting distinct rows from a table using combination of two columns

Status Time Handel Title --------- ------------ ------ ------------- CREATED 2009-10-16 03:37:38+01 902D8 Mozilla Firefox ACTIVATED 2009-10-16 03:37:38+01 902D8 -?- ACTIVATED 2009-10-16 03:37:41+01 902D8 -?- ACTIVATED 2009-10-16 03:37:41+01 E030E Windows Live Messenger DESTROYED 2009-10-16 03:37:4...

Date Difference, Excluding certain Times and Dates

Hi Folks. I'm looking for a way to determine the difference between two dates. A normal SQL DATEDIFF statement won't cut it because I need to excluded non working Hours and days Namely Weekends and any time between 16:00 - 7:00. Something similar to the NETWORKDAYS function in excel. I'm codeing an excel spreadsheet. Using VBA connec...

Is it possible in Oracle SQLDeveloper to prefetch certain tables’ metadata and keep it cached locally ?

I am working on a remote database which has several master tables. the meta-data & the actual data in these tables changes rarely. When querying DB involving these tables and using certain functions (Ex: ctrl+space to auto-complete a table/column name), it takes too long to query the remote DB to fetch this data since its not cached loca...

sum of Times in SQL

Hello all, I have some records like this: ID Personel_Code Time --- ------------- ------ 1 0011 05:50 3 0011 20:12 4 0012 00:50 I want to have the sum of times for each person. in this example I want to have the result like this : Perso...

sql server : get default value of a column

Hello, I execute a select to get the structure of a table. I want to get info about the columns like its name or if it's null or if it's primary key.. I do something like this ....sys.columns c... c.precision, c.scale, c.is_nullable as isnullable, c.default_object_id as columndefault, c.is_computed as iscomputed, but for default value...

sql sum data from multiple tables

I have 2 tables AP and INV where both have the columns [PROJECT] and [Value]. I want a query to return something like this : PROJECT | SUM_AP | SUM_INV I came up with the code below but it's returning the wrong results ( sum is wrong ). SELECT AP.[PROJECT], SUM(AP.Value) AS SUM_AP, SUM(INV.Value) AS SUM_INV FROM AP INNER JOIN INV ON...

How to set a filter for an estimated maximum price

I cannot figure out how to set an estimated maximum price for a collection of records. What I want to avoid is to simply use SQL MAX, because maybe there are records with exorbitant prices. For example, in the "computers-hardware" category of OLX (http://www.olx.com/computers-hardware-cat-240) the filter for maximum price is estimately...

SQL query giving "not a GROUP BY expression" error

SELECT SUM(a.Clicks) AS Clicks, SUM(b.NoOfUsers) Users, c.WEEK_NUM, b2.ALL_TASKS FROM (SELECT SUM(CLICK_CNT) AS Clicks, TO_CHAR(RQST_DT,'YYYY-MM-DD') AS DATEE FROM PER_DAY_USAGE GROUP BY RQST_DT) a, (SELECT TO_CHAR(RQST_DT,'YYYY-MM-DD') AS DATEEE, WEEK_NUM FROM TIMEDIM) c, (SELECT NoOfUsers, accDate FROM...

How to check if resultset has only one row or more?

How to check if resultset has only one row or more? ...