sql-server

How do I convert my CASE WHEN THEN statement?

Please help me to convert the below statement: CASE WHEN TITLE IS NOT NULL THEN 'A' WHEN LOCAL_TITLE IS NOT NULL THEN 'B' END AS COMBINED_TITLE to something like this: CASE WHEN TITLE IS NOT NULL THEN COMBINED_TITLE=TITLE WHEN LOCAL_TITLE IS NOT NULL THEN COMBINED_TITLE=LOCAL_TITLE END AS COMBINED_T...

How to discover trigger's parent schema?

To discover all triggers in any given MS SQL Server database, I'm currently querying the sysobjects table (which is fine because it works in MS SQL Server 2000 which I have to support) e.g. SELECT R1.name AS trigger_name, T1.name AS trigger_parent_table_name FROM sysobjects AS R1 INNER join sysobjects AS T1 ...

Using IN with ALL

How can I select the book Id that is listed under every category id I provide as a set of category Ids e.g I want to get the book Ids that are listed under all categories I listed here: (A,B,C,D,...etc) and not that are listed under any of them. the following select statement does not work with my query's conditions: SELECT bookId FROM...

problem with join SQL Server 2000

I have 3 tables - Items, Props, Items_To_Props i need to return all items that match all properties that i send example items 1 2 3 4 props T1 T2 T3 items_to_props 1 T1 1 T2 1 T3 2 T1 3 T1 when i send T1,T2 i need to get only item 1 ...

SQL Server, division returns zero

Here is the code I'm using in the example: PRINT @set1 PRINT @set2 SET @weight= @set1 / @set2; PRINT @weight Here is the result: 47 638 0 I would like to know why it's returning 0 instead of 0,073667712 ...

How to use dbdeploy with SQL Server?

Guys, I need help in setting up dbdeploy for my SQL Server database and MySQL Server. The example in the dbdeploy website does not tell me how to set the drivers for SQL Server and MySQL. Am a bit lost. Sample scripts will be appreciated. Thanks ...

Hints for testing a web application which had a DB migration from SQL 2000 to 2005.

im testing web application(e-learning which having users, content items, reporting,assigning ...) which had a DB migration from SQL 2000 to 2005. If somebody knows what are the area i should focus on testing Please let me know. ...

SQL Server Select Where value LIKE(temporary table value)

Hi guys, bear with me, this may be a long one. Thanks in advance for the help. I have a function in SQL server 2008 that takes a string: 'A,B,C,D' and splits it and creates a table of the values. Values ------ A B C D I now want to search a table (Users) Where a column value is LIKE one of the rows (surname) in the above table. Thi...

SQL Server query plan differences

I'm having trouble understanding the behavior of the estimated query plans for my statement in SQL Server when a change from a parameterized query to a non-parameterized query. I have the following query: DECLARE @p0 UniqueIdentifier = '1fc66e37-6eaf-4032-b374-e7b60fbd25ea' SELECT [t5].[value2] AS [Date], [t5].[value] AS [New] FROM ( ...

How do you know when an SQL database needs more normalization?

Is it when you're trying to get data and there is no apparent easy way of doing it? When you find something should be a table on it's own? What are the laws? ...

SQL Server 'object'/'property' relational tables linking to other tables

Excuse the poor title, i can not think of the correct term. I have a database structure that represents objects, objects have types and properties. Only certain properties are available to certain types. i.e. Types - House, Car Properties - Colour, Speed, Address Objects of type car can have both colour and speed properties, b...

SQL UPDATE Loop Non-Sequential Keys

I am writing a C# application that will update the fields in a SQL Server database. The current algorithm I am testing simply pulls the data from a "State" field, stores each value in an ArrayList, capitalizes it, and then writes it back to the database. I am having a problem with logic. I pull all of the values into the ArrayList and c...

SQL Server replace, remove all after certain character

My data looks like ID MyText 1 some text; some more text 2 text again; even more text How can I update MyText to drop everything after the semi-colon and including the semi colon, so I'm left with the following: ID MyText 1 some text 2 text again I've looked at SQL Server Replace, but can't think of a viable w...

SQL query to get the sum and the latest enries

I have a table called machineStatus: ID Successfiles totaldata Backupsessiontime > 1 3 988 1256637314 > 2 21 323 1256551419 > 3 8 23 1256642968 > 4 94 424 1256642968 > 1 42 324 1256810937 > 1 0 433 1256642968 Now here i want to group by ID where the successfiles and total data gets summed up, but only display ...

Reset SQL Server execution plan

I've looked all over for this command....what's the command to reset the SQL Server's execution plan? ...

Updating foreign key values

Hello, I have a database application in which a group is modeled like this: TABLE Group ( group_id integer primary key, group_owner_id integer ) TABLE GroupItem ( item_id integer primary key, group_id integer, group_owner_id integer, Foreign Key (group_id, group_owner_id) references Group(group_id, group_owner_id) ) We ha...

Using a SubQuery in an Insert Statement in SQL Server 2005

I have a carsale project. It completely works on localhost. I have a "AddCar.aspx" page that inserts a car record with car's features. Car features are selected with checkboxes. If i don't check any checkbox, there is no problem. But if i check one of feature checkboxes, my page gives an error like this: "Subqueries are not allowed i...

AJAX to do Real Time DB Polls like Twitter's "Real Time Results" in Coldfusion

Hello All, I want to do something similar to the way twitter searches use AJAX to create the "Real-Time Results".. It seems that the database is polled every 15 seconds or so and the number of new records is displayed to the user after each pull. I am working on a Coldfusion 8 server with a MS SQL database and I need to implement some...

How do I know if record from an SQL database is being used elsewhere?

Is there a way to know that a record is being used by another record in the database? Using deleting as an example: When I create an SQL statement trying to delete a group in dbo.group I get this error: The DELETE statement conflicted with the REFERENCE constraint "FK_MyTable". The conflict occurred in database "MyDB", table "dbo.U...

SQL Server hosting only offers 1GB databases. How do I split my data up?

Using ASP.NET and Windows Stack. Purpose: Ive got a website that takes in over 1GB of data about every 6 months. So as you can tell my database can become huge. Problem: Most hosting providers only offer Databases in 1GB increments. This means that every time I go over another 1GB, I will need to create another Database. I have absolu...