sql-server

[SQL Server 2005] Function split string into decimals?

I'm currently trying to write a SQL Server 2005 function, which gets a string as parameter and creates a table with decimal values out of it. The problem is, that I have to define the decimal type based on parameters. This not working snippet should demonstrate the idea: CREATE FUNCTION [dbo].[ufn_ParseDecimal] ( @Sequence VARCHAR...

TSQL: Get Letter representation for a Number

Are there any built in functions for SQL where I can pass in a number and it returns a Letter that matches the number. Example, I supply a 6 and it returns a "F" I realize its an incredibly long shot, just don't wanna re-invent the wheel ...

SQL Server Migration restore backup vs copy data and log files

Hey guys, I'm tasked with doing a SQL Server 2000 to 2005 migration. I will be doing a side-by-side migration. I've read from a few different sources that I can either: perform a backup of the database on SQL Server 2000, ship that backup to the new hardware and restore the database in SQL Server 2005; or detach the database on SQL Ser...

Cascade on delete performance: Whats the fastest way to delete a row its 1-Many rows?

I have a database in which there is a parent "Account" row that then has a 1-Many relationship with another table, and that table has a 1-Many relationship with another table. This goes on about 6 levels deep (with Account at the top). At the very bottom there could possibly be thousands (can even go beyond 100k) of rows. On each tabl...

Implement data rollback in existing CRUD app

I have an existing CRUD app that I have been tasked with implementing "tomb stoning". I need a way to allow a user to roll a given page of data back to the previous state. Say I have First Name, Last Name, and Social Security Number on a page in this app. User A updates the Last Name field. Later, User B notices that the New Last Nam...

Can't enumerate SQL Server 2008 Registered Servers with SMO

Hi there, I had SQL Server 2005 Management Studio installed on my workstation. I have since installed SQL Server 2008 workstation tools and removed the SQL Server 2005 tools. I am now writing a c# program which iterates my registered servers in management studio. Problem is, it is iterating through my old list in the 2005 tools (which h...

SQL Server - Efficiently storing the results of a query in a tracking table

I have been asked to keep track of how many times each item comes up within the results of a particular query. My thought is to just store the result of a query into a tracking table and then spit the results back to the caller. I am wondering what the most efficient method of storing these results would be since the result set could i...

SQL for making suggestions when no results found.

Hi. Would really appreciate some help with a search angine I'm trying to make for a karaoke music site using ASP.NET and SQL SERVER... I have a table called Discs which has the following fields: ID, DiscCode, DiscTitle, DiscType, Theme, Manufacturer There is also a table called Tracks with the following fields ID, DiscID, A...

sql server, cascade delete and parent/child table

i have one simple table with following columns: id, name and parentID i created relationship diagram between id and parentID (on a same table), like simple tree, on the same table, but when i tried to user cascade delete it was disabled for me i know that it will be recursive delete if i will delete parent it will delete his children ...

Snapshot on, still deadlocks, ROWLOCK

I turned snapshot isolation on in my database using the following code ALTER DATABASE MyDatabase SET ALLOW_SNAPSHOT_ISOLATION ON ALTER DATABASE MyDatabase SET READ_COMMITTED_SNAPSHOT ON and got rid off lots of deadlocks. But my database still produces deadlocks, when I need to run a script every hour to clean up 100,000+ rows. Is...

Is this a good or bad way of generating random numbers for each record?

A colleague of mine discovered a behaviour in SQL Server which I was unaware of. CREATE VIEW dbo.vRandNumber AS SELECT RAND() as RandNumber GO CREATE FUNCTION dbo.RandNumber() RETURNS float AS RETURN (SELECT RandNumber FROM vRandNumber) GO DECLARE @mytable TABLE (id INT) INSERT INTO @mytable SELECT 1 INSERT INTO @mytable SELECT 2 INSE...

Problem with SQL Merge Statement

Source Table Id, Name, Address 1 A #202 1 A #203 1 A #204 2 A #202 Target Table Id, Name, Address 1 A NULL After Merge Id, Name, Address 1 A #202 2 A #202 I am using this SQL create table #S (ID int, Name varchar(25) NULL, Address varchar(25) NULL) create table #T (ID int, Name varc...

SCOPE_IDENTITY And Instead of Insert Trigger work-around

OK, I have a table with no natural key, only an integer identity column as it's primary key. I'd like to insert and retrieve the identity value, but also use a trigger to ensure that certain fields are always set. Originally, the design was to use instead of insert triggers, but that breaks scope_identity. The output clause on the insert...

Help on understanding multiple columns on an index?

Assume I have a table called "table" and I have 3 columns, a, b, and c. What does it mean to have a non-clustered index on columns a,b? Is a nonclustered index on columns a,b the same as a nonclustered index on columns b,a? (Note the order). Also, Is a nonclustered index on column a the same as a nonclustered index on a,c? I was look...

What do you do in SQL Server to CREATE OR ALTER?

The year is 2009 and SQL Server does not have CREATE OR ALTER/REPLACE. This is what I do instead. IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'SynchronizeRemoteCatalog' AND ROUTINE_SCHEMA = 'dbo' AND ROUTINE_TYPE = 'PROCEDURE') EXEC ('DROP PROCEDURE dbo.SynchronizeRemoteCatalog') CREATE PROCEDURE dbo.Syn...

Splitting a Table over multiple pages in SSRS

I'm using SQL Server Reporting Services 2008 to produce an invoice. The layout of this invoice is fairly standard - a page header/footer, then some address details at the top, followed by a single table for the invoice lines, and a set of rectangles for the totals below the table. This report worked absolutely fine in SSRS 2005, but s...

SQL Server equivalent to MySQL enum data type?

I have been trying to find out if the data-type enum exists in SQL Server 2008 like the one you have in MySQL. ...

[SQL Server] Valid UPDATE, INSERT syntax?

Are these statements valid? UPDATE Table1 FROM (SELECT * FROM Table2) INSERT INTO Table1 (SELECT * FROM Table2) ...

Denormalize data or multiple-column key?

I'm trying to make a judgment call in implementing a small-ish SQL Server '08 database. I'm translating an output text file of a flat-file database from an old COBOL system to the aforementioned SQL Server database. It's a database of vehicle and real estate loans, which can be uniquely identified by the combination of a Lender ID (a s...

Cross Tab - Storing different dates (Meeting1, Meeting2, Meeting 3 etc) in the same column

I need to keep track of different dates (dynamic). So for a specific Task you could have X number of dates to track (for example DDR1 meeting date, DDR2 meeting date, Due Date, etc). My strategy was to create one table (DateTypeID, DateDescription) which would store the description of each date. Then I could create the main table (ID, ...