sql

How do you decide what process to kill in SQL Server Activity Monitor?

Hi, I am not a Db guy. But sometimes I am asked to check Db and see if there are some processes blocking the Db and if yes, KILL! Can you explain me what is the best way of reading the Activity Monitor in terms of finding the right process candidates to be killed? What columns to be checked first and against what values? thank you, ...

Simple MySQL question - MAX(field) ?

Hi just a simple question I know how to get the most recurring field from a table SELECT MAX(field) FROM table But how do I get the Second most recurring field from a table? Thank you. ...

SQL Server: how do I SUM column values if the name of the column contains a word?

In my SQL table: Period| Brand A small Bags| Brand A big bags| Brand D Shoes| ...| Brand X Shoes 2010 | 10 | 20 | 30 | ...| 200 How do I sum columns that contains certain words (e.g shoes) in the column names ? Expected results: Period | Sum of Bags | Sum of Shoes | .. 2010 | 30 ...

SQL: LIKE where condition specifying a letter followed by a number followed by anything else?

Hi, Is it possible to write a WHERE condition in MS SQL Server that will grab rows that: begin with a specified letter then have a decimal then anything else I basically have a table that contains postcodes and I want all postcodes that belong to Birmingham - B followed by a number. Some postcodes are in there that start B and then a...

Sql: Unique field contraint (slug) across multiple tables (doctrine/symfony)

I have a number of tables that will be looked up using the url 'slug'. For example 'news' and 'blog' both have the 'slug' field, which is defined as a unique field in the doctrine database schema. Is there any way I can extend this uniqueness across both tables: for example if there is a news article with slug= "good-story" then it will...

Complicated SQL query

I'm trying to build a specific sql query but i have no idea how to implement what i want. My database looks like this: Col1 Col2 "a" 5 "b" 7 "a" 8 "a" 7 "b" 5 "b" 7 "c" 3 "a" 4 "b" 3 "b" 4 "c" 1 And I want a query that returns something like this: "a" 8 "a" 7 "b" 7 "b" 7 ...

sql syntax how to write it down in java

i want to write this line in an sqlight db b: CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US') therefore in my java file who generate this data base i am doing : stat.executeUpdate("create table "+"android_metadata"+"("+"locale"+ " TEXT DEAFULT"+");"); PreparedStatement prep1 = conn.prepareStatement( ...

pulling a column total into another column as part of the ref

Hi there again, have been puzzling this query and haven't quite got it. Below is where I am up to and below that is the result. It returns the line total and not the column total, any help appreciated. SELECT TOP (100) PERCENT 'SA' AS Doc_Type1, 'A' + SUBSTRING('000000', 1, 6 - LEN(CAST(dbo.companies.companyId AS VARCHAR(10)))) + CA...

ISQL app migration option, Progress - "OpenEdge" Personal RDBMS with 4GL(ABL) development system?

Back in 1985, when I was a Product Planner for AT&T-IS Labs (Unix Product Management), one of my primary duties was to evaluate emerging 4GL/RDBMS products, submit product plans and recommend whether AT&T should pursue a co-marketing or co-labeling agreement with the vendor or just test/certify it as compatible on our 3B-series systems. ...

isnull vs is null

I have noticed a number of queries at work and on SO are using limitations in the form: isnull(name,'') <> '' Is there a particular reason why people do that and not the more terse name is not null Is it a legacy or a performance issue? ...

PostgreSQL count() and arrays

I have a table that looks like this: episodes ------------------------------------------------------------ id (PK serial) | show_id (int4) | episode_number (int2[]) ------------------------------------------------------------ 1 | 1 | {1} 2 | 1 | {2} ...

SQL query to find rows that aren't present in other tables

Here's what I'm trying to accomplish: I've got two tables, call them first and second. They each have an ID column. They might have other columns but those aren't important. I have a third table, call it third. It contains two columns, ID and OTHERID. OTHERID references entries that may or may not exist in tables first and second. ...

Alternate names for a surrogate key/sequence number/ID column

I have a legacy table that has as a part of its natural key a column named <table_name>_IDENTIFIER and it seems like it would be confusing to create a surrogate key named <table_name>_ID or ID so I'm leaning towards naming it SURROGATE_KEY. All my other tables use the <table_name>_ID syntax. Any better suggestions? ...

SQL - Where Clause by Another Select Statement?

I have the following query: select r.people_code_id [People Code ID], r.resident_commuter [Campus6], c1.udormcom [AG], aR.RESIDENT_COMMUTER [AG Bridge], ar.ACADEMIC_SESSION, ar.ACADEMIC_TERM, ar.academic_year, ar.revision_date from RESIDENCY r left join AG_Common..CONTACT1 c1 on r.PEOPLE_CODE_ID=c1.key4 left join AG_Common..CONTACT2 c2 ...

Search products with parent and child categories

Hello I'm building a shopping cart website and using SQL tables CATEGORY Id int, Parent_Id, Description varchar(100) Data: 1 0 Electronics 2 0 Furniture 3 1 TVs 4 3 LCD 5 4 40 inches 6 4 42 inches PRODUCTS Id int, Category_Id int Description... Data: 1 5 New Samsung 40in LCD TV 2 6 Sony 42in L...

How to export from ASP.NET to Powerpoint 2007 ?

Hello, I'm working on a project that I'm trying to export data from textboxes in asp.net website project to a powerpoint file. I writing ofcourse in C#. The whole concept is to use the data the a user inserts to the text boxes and they are sent after clicking a OK button directly to a powerpoint file. I'm using OFFICE 2007 so I'm using ...

SQL query join question

How do you do SQL query for the following condition? Suppose you have two tables: table1 and table2, where each entry in table1 can have multiple corresponding entries in table2. The pseudo code for the query that I want is: for each $row in table1 $rows = find all rows in table2 that corresponds to $row with $row.id == table2.foreig...

Roles of parentheses in SQL Server SELECT queries?

Hello, The following query returns no result and no error on SQL Server 2008 (tested on SP1), you can run it against any database, even master: WITH computed_table (id) AS ( SELECT id FROM this_table_does_not_exist ) (SELECT * FROM computed_table) UNION (SELECT * FROM another_table_that_does_not_exists) On SQL Server 2005, you ge...

SQL Server 2008. I created an instance of SQL Server. My user domain has since changed. How do I reconfigure SQL for my new user domain?

I created an instance SQL Server on my local machine. Then my login changed and I was assigned a new domain. As a result, I need to reconfigure SQL Server. The owner of the instance is still myself with the old domain. I need to change that to the new domain. Then I need to change my .Net apps so that they can connect to this instance. ...

How can I do this in SQL? I need to find possible permutations of a small table of data

Hi All, I have this small table of data. Dir LinkL LinkH East 19 27 East 27 29 East 29 31 West 46 49 West 49 51 West 51 61 These represent possible trips. How can I query this? For instance if you started at station 19, you could go from 19->27, 19->29, and 19->31. Three possible "trips" But starting from 2...