sql

Can I use non-aggregate columns with group by?

You cannot (should not) put non-aggregates in the SELECT line of a GROUP BY query. I would however like access the one of the non-aggregates associated with the max. In plain english, I want a table with the oldest id of each kind. CREATE TABLE stuff ( id int, kind int, age int ); This query gives me the information I'm aft...

SQL reseeding works but auto increment starts at 0

I have some table that have an identity column that I am trying to reseed. The reseeding works (I think) but when a new data item is inserted into the table the identity column starts at 0. My code to reseed is: DBCC CHECKIDENT(MyTable, RESEED, 0) The Identity Specifications for the tables are: Identity Increment = 1 Identity Seed =...

Stored Procedure with conditional results

I want to write a stored procedure that works something like this: SELECT * from T where T.A = @a and T.B = @b if that returns rows, return those rows, if not, return SELECT * from T where T.A = @a and T.B IS NULL Edit: It feels that there should be a way to create a procedure such that it runs the first query once and runs the se...

Force SQL to Add Rather than Concatenate Two Columns?

I have column OFF_SAT_COMP.LINKACCT and OFF_SAT_COMP.COUNTRY. I am trying to add the values of these two columns in a given row together, but when I do so as follows: (OFF_SAT_COMP.LINKACCT + OFF_SAT_COMP.COUNTRY) It is concatenating rather than returning the sum of the two column values. e.g. It is returning 500300 where I want 800. ...

sql access how to return between dates

How do I specify a date range in MS Access? Is the below query correct? Do I have to put "2/1/2010" in quotes? Or do I have to do something like date(2/1/2010)? SELECT [Occurrence Number] as Fld FROM [Lab Occurrence Form] WHERE [Practice Code]="ACCIM" AND [1 0 Preanalytical (Before Testing)]="1.1 Specimen Mislabeled" AND ([Occu...

Can you bypass the size limit of SQL Server Express by stacking databases?

My company is working on a development project using SQL Server 2008 Express. The amount of data we plan to store in our main table will quickly exceed the 4GB size limit of Express. We can buy ourselves some time with SQL Server 2008 R2, but eventually we will surpass the 10GB limitation as well. The team lead wants to hear all availab...

Data Pagination: SQL Server 2005 + SL3

Hey everybody, got an interesting question I think. I've got a Silverlight3 application which is querying a SQL Server 2005 database asynchronously. However, some of the data sets the queries return are massive and so I'm looking into data pagination. Goals: 1) Just in time data calls - I only want to query for page 3's data when the ...

Can a table field contain a hyphen?

I have a table in a MySQL table with a fieldname 'product', and want to rename it to 'ds-product'. The CMS type system I am using uses the id of formfields as the name of the table field to insert into. For most this works fine, but for a particular field it prepends 'ds-' to whatever ID I give it, so I must make the table field name m...

Nested Create Type in Stored Procedure Declaration T-SQL

I am writing a SQL Stored Proc which takes in a single table valued parameter. Is it possible for me to create the table type in the parameter definition, for example: CREATE PROCEDURE example ( @param (CREATE TYPE tableparameter ( column1 int, colunn2 varchar.... )) READONLY ) ...

Why is SQL Query Returning Duplicates?

I have the following query. What is strange is that it is returning multiple records for the same individual - but it should be returning just one row for each individual. It is all LEFT JOINS based on CONTACT1 C - which has only one row for each individual, unlike the other columns which sometimes have multiple rows for the same individ...

MySQL string split

I uploaded a csv file to MySQL DB but for some reason data from two columns got glued to one. e.g. the data 0880174V,D should have gone to two different columns. Is there a way (via sql) i can split the data from this column (i.e. as 0880174V and D) and update the table, without having to delete the record and re-upload? I have a milli...

Why is this query so slow?

I have tables FOO and BAR. FOO has a foreign key to BAR's PK. When I execute the following query it takes several seconds. select foo.name, foo.description, bar.quadrant from FOO, BAR where FOO.BAR_ID = BAR.BAR_ID Here is my explain plan: OPERATION OBJECT_NAME OPTIONS COST SELECT STATEMENT ...

Which framework and database should i use?

I am looking at creating an application to record gym workout(set,reps, etc) and I was wondering what framework and database backend to use. I am currently thinking C# .Net 3.5 for the framework because I am familiar with it but I'm unsure about how to store the data. Originally I was thinking of xml files and parsing through them but th...

Complicated SQL query - Finding a set of something, counting it, then finding a subset of the first set, and counting that

I have three tables, we'll call them table1, table2, and table3. Lets say each table has a user id column and a date column. What i'd like to do is to be able to count the number of rows with a specific user id in table1, and sum it with the number of rows with that user id in tables 2 and 3. I'd then like to take that first query I d...

Change name of stored procedure in SQL Server 2008

I have a stored procedure which I edit through Visual Studio 2008. Is there a simple way to change the name of the stored procedure? Right now if I look at the sproc's properties, the name of the sproc is grayed out. ...

Utility to create an ERD from an already existing MySQL DB?

I have my database built already, but I really want to print out an erd to reference while I'm building my models. Is there a utility that can generate an erd from a SQL dump or by connecting to the database directly? Thanks in advance, ~Brandon ...

Monitor Database Updates Live using AJAX and SQL

How can one trigger an event locally when a field in a connected database changes? I've done some research but it seems like there there are varying and inconclusive answers to the question. I'm building an application where users rate comments, and I'd like to have the ratings change live when they are modified by a different user. For...

Why does this sql query do a key lookup?

I have a table User with a bunch of indexes. One of them is a unique index on the AccountIdentifier column. Since this is a unique index, why is a key lookup required in addition to the index seek? The index seek tooltip reports that only one record is returned. I've also tried converting the index to a "unique key" type. ...

Suggestion For Finding Similar Rows In Mysql

Hi, i want select similar rows accourding to row's title columun. Title columun has mostly have 5 or 6 six keywords. Which algorithm do you recommend ? Soundex Maybe ? P.S: Title columun has unicode chracters like Ç, Ö, Ş... ...

Using SQL Server Fulltext Search with a Union View

Hello, I have a view which combines two tables via UNION ALL. The view is also schemabound, if that matters (WITH SCHEMABINDING). Is it possible to enable fulltext search on this view? I understand that Fulltext Search requires a unique index, but I can't create it because of UNION. Is there another way to make Fulltext Search work on...