sql

Adding a SUM Column to a Query

I'm trying to do a query that returns the information of a purchase bill, but also there's another table that has detail of the bill, but I need to add that total to the other query, but I can't add the column, because it says that I need to have in the group by the same objects that in the select, and I tried it this way, but it says th...

Declaring DB connection in static void - will the connection pool persist?

Hi, I have a multithread server that uses one MSSQL which each client should have access to. I wanted to use connection pooling also I am using this: public static void DBconn() { SqlConnection pripojeni = new SqlConnection(); pripojeni.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial...

SQL for summing only new values

Hi, i have a table like this NAME VALUE ----------------- bla 1 bla 2 bla 2 bla 3 bla 1 bla 4 bla 2 How can i do a sum of ONLY different values , and ignore the repeating values (is it possible?)? Something like this : SELECT SUM(??condition?? value) as total FROM table And the sum should be...

What is the difference between SQL Azure and SQL Server 2008?

Hi, now I'm looking on Azure and want to migrate on this one. But I'm not sure that don't get a problems on this way. Could you explain what is the difference? And what I defenetly can't do with SQL Azure? ...

Best Way For Join Parent ID

I have a table named "categories" like this: id int(11) NO PRI NULL auto_increment name varchar(50) NO NULL seo_name varchar(50) NO MUL NULL parent_id int(11) NO NULL total_projects int(11) NO NULL order int(11) NO MUL NULL i...

Help with sql statement

I'm using sql-server 2005 and ASP.NET C#. i have Users table with userId(int),userGender(tinyint),userAge(tinyint),userCity(tinyint). (simplified version of course). I need to select always two fit to userID i pass to query users of opposite gender, in age range of -5 to +10 years and from the same city. Important fact is it always mu...

SQL Server 2008: multiple instances on single computer

Hi. We have one vps server, at the moment, and we need to run both test and prod web applications on it. Is it good idea to have one sql instance for production databases and another one for test databases? Thank you. ...

Count on the same table

Hi, i have got a problem with my SQL Statement: Table structure: CREATE TABLE "tags" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "page_id" INTEGER NOT NULL, "title" TEXT NOT NULL ); Now i want to select all the tags from one page and the frequency of this tag in the whole database. I have the following SQL statement: S...

What´s the single most influential database book or tutorial every DBA should read?

I am looking to learn more about databases (MySQL for starters), particularly about choosing the right approach (e.g. stored procedures vs views and triggers for data aggregation) in a situation. Maybe this example shows what I mean: Yesterday I asked a general SQL question about aggregation of data and received the answer that "it depe...

SQL Query - SELECT all rows except where value in column begins with 402 or 403 or A40

I have a (MS) SQL VIEW with no control over and it also queries several other SQL VIEWs that I also have no control over but must use. Get all rows based on "pilot" value except where it starts with 402 or 403, or A40. This is the current query that works fine as long as all "pilot" entries are possible to interpret as INT. SELECT * fr...

Need help with a simple Join

Oi Right to the problem. SELECT *,t.id AS threadid FROM threads t LEFT JOIN players p on p.id = t.last_poster WHERE t.boardid = $boardid I have two fields in threads called posterid and lastposterid. Which are the IDs of the thread starter / last poster. What I want to do is to get their names from players table. But how? ...

Creating Unique Key in MySQL table referring to date

Greetings to all. Newbie here. Question on preventing duplicated entry in my simple web form. My table record user input from a web form, and distinguished by date e.g. DATE(). How to prevent user with the same name to enter information twice in a single date, e.g. same username cannot be entered twice in the same date, but can be enter...

Couldn't connect to sql server database from ado.net.

Hi there! I wrote simple sql script that creates my database: create database [MaterialStream]; exec sp_addlogin N'MaterialStreamLogin', N'123', N'MaterialStream' exec sp_adduser N'MaterialStreamLogin', N'MaterialStreamUser', N'db_owner' And then couldn't connect to my database from ADO.NET. How can I set up credentials for my user? ...

Generic Stored Procedures

I am writing a stored procedure to handle the populating of a database from csv files. There about 150 tables and there will be 1 CSV file per table. There is some added complication in that data needs to be validated against a validation table on import. I am currently writing a single Store Procedure, that will take the csv file name...

Quick SQL question

I have 3 tables: User (PK userid, ...) Computer (PK computerid, FK userid, FK cpuid, ...) CPU (PK cpuid, ...) So, a user can have multiple computers, and each computer has exactly one CPU. Same cpu can appear in different computers. I would like to get the number of computers and unique CPUs per user. userid | Number of compu...

Hard join. Is it possible?

Hi I need to get the forum name, thread name and post message with the post id 32. Would this be possible to do with 1 query? forums id name threads id forumid subject posts id threadid message ...

Another quick SQL question

I have the following table structure, A -< B represents one A can have many B User -< Computer -< ComputerConfiguration -< Benchmark >- GameVersion >- Game They are connected with PK int keys. One user can have many computers, computer can have many configurations, configuration can have many benchmarks, and benchmark has FK to game ...

SQL: Cluster similar values of column B, yet "order" by column A

Let's say I have a table with two columns, id and hash: id | hash ------------------ 1 | bb 2 | aa 3 | aa 4 | bb I need to order them by id (descending), yet group all the rows that have the same value. An algorithm that did this would be for example: Gather into disjunct subsets the table so that the column...

Is there a generic way to generate an arbitrary linear sequence in SQL?

Is there a SQL query I can do that will generate a linear sequence like 1, 2, 3, 4, 5, 6, 7 ... x+1 or 2, 7, 12, 17, 22 ... 2+5x (where each number is an entry in a row of the resulting table) ...

SQLCE - connection pooling and performance?

Hi, Is it good to have SQL CE with small application server where clients very often read and write to the database? I am not aware of any cons so far. Also, does the connection pooling work here? ...