sql

Summing values for an overview

I want get the time used for a case so I can create an overview. The SELECT query for the cases looks like this: SELECT bc.id, bc.title, bc.estimateCurrent FROM cases bc For one case I can get the used time like this: SELECT SUM(TIME_TO_SEC(TIMEDIFF(dateEnding, dateBeginning))) AS calculatedTime FROM timesheet WHERE `#case` = ? ...

mySQL Performant request to make a count request in a column of each each row of another request

Hi, I have a table with devices, their buyed country and their buyed date. I want to retrieve : - the total number of devices by country - and the number of devices buyed since 1 month for each country. I use this request to make this : SELECT countryCode, COUNT(*) AS sinceBeginning, ( SELECT COUNT(*) FROM mytable WHERE countryCode...

question in sql

Hello, how I can create a query in Oracle for "angel" no matter if it is Angel, ANGEL, angel AngEl ...

What's the best practice of naming stored procedure for t-sql?

I have worked with several big databases and the names of stored procedures were very different: SP_PrefixXXX PrefixYyyXxx Prefix: Rep, Act What's the best practice of naming? How can I organize them in a proper way? ...

Use SELECT inside an UPDATE query.

How can I UPDATE a field of a table with the result of a SELECT query in Microsoft Access 2007. Here's the Select Query: SELECT Min(TAX.Tax_Code) AS MinOfTax_Code FROM TAX, FUNCTIONS WHERE (((FUNCTIONS.Func_Pure)<=[Tax_ToPrice]) AND ((FUNCTIONS.Func_Year)=[Tax_Year])) GROUP BY FUNCTIONS.Func_ID; And here's the Update Query: UPDATE...

Unexpected table scan for id != id

One application causes a heavy load on our Sql Server 2005 database. We don't control the application that runs this query hundres of times a minute: select id,col1,col2,col3 from table where id != id Note the id != id, meaning a row is not equal to itself. Unsurprisingly, the result is always no rows found. However, Sql Server does a...

PL/SQL "SQL Command not properly ended" error

I am currently working on developing some SQL scripts in PL/SQL Developer and I am getting an "SQL Command not properly ended" error that I am unsure how to solve. The code I am using looks something like this CREATE TABLE temp_table as SELECT * FROM table_x INSERT INTO temp_table SELECT * FROM table_y If I execute the two ...

How can I retrieve similar rows from different tables in the same query?

Let's say I have two or more tables filled with users and I want to retrieve all users from those tables in the same query. Tables share some columns and those columns that have the same name are the ones I'm trying to retrieve. Something like: SELECT name, age FROM users1; SELECT name, age FROM users2; etc. Note: this is just an ex...

How to check for the existence of a DB?

Hello all, I am wondering if there is an elegant way to check for the existence of a DB? In brief, how do test the connection of a db connection string? Thanks ...

SQL Server: What is the difference between Index Rebuilding and Index Reorganizing?

Please, can anyone explain me what is the difference between Index Rebuilding and Index Reorganizing? Thanks in Advance ...

SQL Server 2005 Restore Hanging

I have a database showing up in SQL Enterprise Manager as "(Restoring...)" If i do SP_WHO there is no restore process. The disk and CPU activity on the server is very low I think it is not restoring at all. How can I get rid of this? I've tried renaming the underlying MDF file, but even when I do "NET STOP MSSQLSERVER" it tells me t...

Why hasn't SQL Server made a WHERE clause mandatory by default?

It seems like a no brainer to me. I've heard countless stories about people forgetting the WHERE clause in an UPDATE or DELETE and trashing an entire table. I know that careless people shouldn't be issuing queries directly and all that... and that there are legitimate cases where you want to affect all rows, but wouldn't it make sense to...

Inserting a row into DB2 from a sub-select - NULL error

I am trying to insert a row into a table, using a value that is derived from another table. Here is the SQL statement that I am trying to use: INSERT INTO NextKeyValue(KeyName, KeyValue) SELECT 'DisplayWorkItemId' AS KeyName, (MAX(work_item_display_id) + 1) AS KeyValue FROM work_item; So, I am trying to create a row in NextKeyValue t...

Can't connect to SQL Server 2005

Hey all, I just installed SQL Server 2005 on my machine and now I am trying to connect to it via SQuirrel SQL, but I am unfortunately running into problems. When installing SQL Server 2005 I chose mixed mode for authentication and I have set up a new user account with which I am trying to connect. I also have installed the Microsoft SQ...

Show only the first N lines of output of a SQL query.

Is there a way to only show the first N lines of output from a SQL query? Bonus points, if the query stops running once the N lines are outputted. I am most interested in finding something which works in Oracle. ...

custom sql parameter using IN clause in gridview - C#

Hi, When I placed the the following SQL query, SELECT [ItemID], [Name], [RelDate], [Price], [Status] FROM [item_k] WHERE [ItemID] IN (" + itemIDs + ") in gridview custom sql statements, it gets transformed to, SELECT ItemID, Name, RelDate, Price, Status FROM item_k WHERE (ItemID IN ([ + itemIDs + ])) a...

Find SQL objects missing from source control

We use Source Safe and are migrating to Source Gear. We know that we have sql objects (procs, triggers, views, functions) that are in sql but were never added to the source code repository. What is the best way to hunt those down so I can add them? ...

How can I drop multiple columns in DB2 on AIX?

What is the syntax to drop multiple columns in DB2? I tried this: ALTER TABLE work_item DROP COLUMN (TRANSACTION_TYPE, REQUEST_TYPE, LOCATION_CODE, ROLE_ID, SUBMITTED_BY); But it didn't work. I am running on AIX (from what I read, it looks like maybe you cannot drop columns at all on platforms other than AIX). If I drop the columns...

Do you have to have SQL Server installed on a machine if the connection string using is a path to a .mdf File?

I am wondering if you can use Linq to SQL using a .mdf file on a machine without a SQL Server instance installed? ...

using charindex in sql query

hi, I have a string named itemIDs separated by commas(12,43,34,..) and in order to use it as a parameter i need to convert it to int since the itemID in the db is in int format. this is what i wrote but i get an error saying Incorrect syntax near the keyword 'as'. using (SqlCommand searchResult = new SqlCommand("SELECT ItemID, Name, R...