sql

Creating indexes for optimizing the execution of Stored Prcocedures

Hi All, The WHERE clause of one of my queries looks like this: and tbl0.Type = 'Alert' AND (tbl0.AccessRights like '%'+TblCUG0.userGroup+'%' or tbl0.AccessRights like 'All' ) AND (tbl0.ExpiryDate > CONVERT(varchar(8), GETDATE(), 1) or tbl0.ExpiryDate is null) order by tbl0.Priority,tbl0.PublishedDate desc, tbl0.Title asc ...

How to select the same value only once in MysQL?

I have this table: ------- id a b ------- 1 1 1 2 1 5 3 1 1 4 1 1 5 1 6 How do I select this? ------- id a b ------- 1 1 1 2 1 5 5 1 6 ...

How can I use SQL to group and count the number of rows where the value for one column is <= x and the value for another column > x?

I'd like to group and count the number of entries in a table that meet criteria colA <= x < colB Suppose I had the following table: index Game MinAgeInclusive MaxAgeExclusive -------------------------------------------------------- 1 Candy Land 3 8 2 Checkers 5 255 3 ...

Is there a way to avoid conditions in TSQL?

Hi, i'm using sql-server 2005 with asp.net C#. There is a search query on my site with different parameters. fromAge as tinyint toAge as tinyint fromHeight as tinyint toHeight as tinyint gender as tinyint withImage as bit region as tinyint astrologicaSign as tinyint these parameters i get from first time use performs a search and sa...

populating a aggregate table

I have a question target table str_week_day end_week_day age_id usage_ratio eq_type ------------ ------------ ------ ----------- ------- 11-Jul-10 17-Jul-10 1.00 0.5 RECEIVER 11-Jul-10 17-Jul-10 2.00 0.5 HUB 18-Jul-10 24-jul-10 1.00 0.5 RECEIVER 18-Jul-10 24-jul-10 2.00 ...

Use of connection pooling, what is the right way?

seen question about that today but I not sure whether I understand it well. Also using the same connection string causes that they will "share" connections (if free), right? So is it OK to have class like that, pass it as a reference to each client in multithread app and just call its methods. Anyway, would not there be a short lag in th...

SQL Synchronization

I have done SQL synchronization. I am to execute the Query like Insert,Update,Delete and it is affecting /reflecting in another PC, but if I create a table it is not replicated in another PC. How do I create a Table that is reflected in another PC which I synchronized. SQLProduct:MsSql Server 2008 Please help ...

Variable scope in SQL `order`.id unknown column

In the following query, the error Unknown column 'order.id' in 'on clause' is being thrown by my order.id reference in the INNER JOIN. The id column does indeed exist. Any ideas why it's not accessible via the sub query? SELECT SUM(price+shipping_price) AS total_sales, COUNT(id) AS total_orders, AVG(price+shipping_price) A...

Group by / distinct combined with sum?

Hello to all! I have a sql statement like this: select a.id, a.valfrom ... inner join ... where ...; As a result I have this: id val --------- 3 10 3 10 3 10 9 21 9 21 11 2 11 2 13 30 So you can see, one id has one value. If I do a group by (a.id), I get: id val --------- 3 1...

Checking the integrity of the data for an entity

I have three tables STUDENT, DEPARTMENT and COURSE in a University database... STUDENT has a UID as a Primary key -> which is the UNIQUE ID of the student DEPARTMENT has Dept_id as a Primary Key -> which is the Dept. number COURSE has C_id as Primary Key -> which is the Course/subject Id I need to store marks in a table by relating the ...

SQL report from 3 tables with SUM of fields

i have 3 tables see the picture i want the sql statement which produde report like Required Report in pic. ...

TSQL Average Column By Distinct Entries In Another Column

I start with a table looking like this... +-------------------------+ | procName | TimeEnded | +-------------------------+ | A | 04:00:00.000 | | B | 04:01:00.000 | | C | 04:03:00.000 | | A | 04:06:00.000 | | B | 04:10:00.000 | | ... | ... | Run a query to generate a RunTime column,...

How do I change all empty strings to NULL in a table

I have a legacy table with about 100 columns (90% nullable). In those 90 columns I want to remove all empty strings and set them to null. I know I can: update table set column = NULL where column = ''; update table set column2 = NULL where column2 = ''; But that is tedious and error prone. There has to be a way to do this on the whole...

Retrieving i18n data with fallback language

I have to grab i18n text from a database. The default language is English, it has text for everything. But the non-English languages doesn't necessarily have all the desired translations. If a non-English translation for a certain entity/key isn't available in the DB, then I'd like to have it to return the English text instead. So, Engli...

Using items from List<string> in SQL query

Ok, I have a list that consists of a bunch of values from a sql query, that part works fine. What I want to do is use the items in that list to tell another query what to look for. So, what it is saying is that, it should return all columns from CMMReports where PartNumber is like %listItem1..2...3%, Any advice? List<string> ImportedPar...

VB.NET - SqlException: Could not locate entry in sysdatabases for database...

Hello, I want to backup my database using Linq to SQL: Dim sql As String = "BACKUP DATABASE SeaCowDatabase TO DISK = _ '" + sfd.FileName + "'" db.ExecuteCommand(sql) But instead, I get this error: System.Data.SqlClient.SqlException (0x80131904): Could not locate entry in sysdatabases for database 'SeaCowDatabase'. No entry fo...

SSMS: connecting to a network server database

i need to connect to a database that is on a different server on the company network i am using sql server 2005 i went to connect to server --> browse for more --> Network servers but in the network servers list i am not seeing the server that i need. how do i find the server that i need and connect to it? ...

Multithreading Help w/Powershell

So I have a script that will go through and ping all the servers from a list that is stored in SQL Server. The script works fine but it does it all sequentially (lame). Can someone help me out as to how I would change this to use multithreading instead of a foreach loop? $Server = "ServerName" $Database = "DatabaseName" $con = ...

Best Isolation Level to avoid deadlocks using an UPDATE sentence in Sql Server 2005

i need execute un update statement over an sql server table, this table is used by another process at the same time. because that sometimes deadlocks ocurs. wich Isolation Level do you recomend to avoid or minimize this deadlocks? ...

how to use .bak files

Hey, i want insert .bak in my asp.net project, how to use .bak file? I use ms sql 2008 express. ...