sql-server-2005

SSIS in sql server 2005

I've created a SSIS package, in which I'm calling 2 sp's with a single parameter each. So how to call this package inside a stored procedure by passing a value to as parameter to that package and stored procedure dynamically. ...

What is the best way to create and populate a numbers table?

I've seen many different ways to create and populate a numbers table. However, what is the best way to create and populate one? With "best" being defined from most to least important: Table created with optimal indexing rows generated fastest simple code used to create and populate If you don't know what a numbers table is, look he...

How to store Vietnamese characters in SQL Server 2005?

I wanted to add my colleague's information in my database for testing purposes. Since he his from Vietnam, his name has a special Vietnamese character in it ('ơ'). When I updated the database, the character was transformed to a regular 'o'... How can I store that kind of special character inside SQL Server Express 2005? ...

Selecting one row from duplicated rows

I have a loooooong stored procedure that runs about 15 select statements across different tables in a database - I am inserting all the results of the selects into a temporary table. However - that table has some rows that are exact duplicates. The temporary table looks something like this: DocID | VisitDate | DocName 824...

Which is better: Bookmark/Key Lookup or Index Scan

I know that an index seek is better than an index scan, but which is preferable in SQL Server explain plans: Index seek or Key Lookup (Bookmark in SQL Server 2000)? Please tell me they didn't change the name again for SQL Server 2008... ...

Return temp table of continuous dates

I need to create a function that returns a table of continuous dates. I would pass in a min & max date. I expect it to be able to be called like this: SELECT * FROM GetDates('01/01/2009', '12/31/2009') I currently have a stored proc that does this, but requirements changed and now I need to do include the returned data from within a ...

Get a table count in SSIS from an Oracle view

In my SSIS package, I want to see if a particular Oracle view has data in it. I have a Execute SQL Task with a select count statement: Select CAST( count(*) as Integer) As Row_Count from OWNER.VIEW_MV My RowCount is in the Result Set, pointing to my Variable User:TableCount. If I set TableCount to anything except Object, I get an err...

Why does 'HASH JOIN' or 'LOOP JOIN' improve this stored proc?

I have a basic query that goes from 6 seconds to 1 second just by changing one join from LEFT JOIN to LEFT HASH JOIN or 'LEFT LOOP JOIN'. Can anyone explain why this would cause such a large increase in performance and why SQL's optimizer isn't figuring it out on it's own? Here is roughly what the SQL looks like: SELECT a.[ID] FROM...

SQL statement to insert record into table that has identity column?

Hello SO: I am attempting to insert a row manually into my SQL Server data table. This table has 5 columns, one identity and four data columns. I looked at this post, but when I run the selected answer's query (after replacing 'GroupTable' with my table name of course), my SQL Server 2005 management studio crashes. I have tried variati...

Difference in behavior for SET IDENTITY_INSERT from SQL Server 2000 to 2005?

I have an application that (currently) needs to uses DBs served by both SQL Server 2000 and SQL Server 2005. I'm trying to move a DB programmatically from one server to the other. All of the tables I use each have a primary key that is autoincremented. Since these autoincremented keys are used as foreign keys in other tables, my plan ...

How to Implement Breadcrumbs for nested Categories

My categories can be nested about 6 levels deep at most. The problem I am having is getting the breadcrumb array or list from the database (sql server 2005). My sql skills are not that great. Once I get the breadcrumb from the database what would be the best way to present it. ...

Indexing Speed in SQL

Hi, When creating indexes for an SQL table,if i had an index on 2 columns in the table and i changed the index to be on 4 columns in the table, what would be a reasonable increase the time taken to save say 1 million rows to expect? I know that the answer to this question will vary depending on a lot of factors, such as foreign keys, ...

Can there be constraints with the same name in a DB?

This is a follow-on question from the one I asked here. Can constraints in a DB have the same name? Say I have: CREATE TABLE Employer ( EmployerCode VARCHAR(20) PRIMARY KEY, Address VARCHAR(100) NULL ) CREATE TABLE Employee ( EmployeeID INT PRIMARY KEY, EmployerCode VARCHAR(20) N...

Date Range Intersection Splitting in SQL

I have a SQL Server 2005 database which contains a table called Memberships. The table schema is: PersonID int, Surname nvarchar(30), FirstName nvarchar(30), Description nvarchar(100), StartDate datetime, EndDate datetime I'm currently working on a grid feature which shows a break-down of memberships by person. One of the requirem...

How can I query rankings for the users in my DB, but only consider the latest entry for each user?

Lets say I have a database table called "Scrape" possibly setup like: UserID (int) UserName (varchar) Wins (int) Losses (int) ScrapeDate (datetime) I'm trying to be able to rank my users based on their Wins/Loss ratio. However, each week I'll be scraping for new data on the users and making another entry in the Scrape table...

How to get distinct values from columns?

I have a query that returns a result set similar to the one below A | B | C | D -----|----|----|----- 1 abc | d0 | e0 | true 2 def | d0 | e1 | true 3 ghi | d0 | e2 | true 4 jkl | d1 | e1 | true 5 mno | d2 | e2 | false In Column A each value is unique. but column B,C,D have some duplicate values. ...

VB6 SQL 2005 Database Index Question

I have a VB app that accesses a sql database. I think it’s running slow, and I thought maybe I didn’t have the tables propery indexed. I was wondering how you would create the indexes? Here’s the situation. My main loop is Select * from Docrec Order by YearFiled,DocNumb Inside this loop I have two others databases hits. Select *...

SQL Query - Copy Values in Same Table

So I have a table that looks like this: ProjectID TaskID Date 000 001 10/28/09 000 002 12/1/09 000 003 02/24/10 001 001 04/14/10 001 002 07/5/10 001 003 02/24/11 002 001 06/07/10 002 002 07/7/10 002 ...

SQL Conditional on Bit

Why does this.. DECLARE @SkyBlue Bit SET @SkyBlue = 1 IF @SkyBlue Select 'the sky is blue!' ELSE Select 'the sky is not blue!' Produce this "An expression of non-boolean type specified in a context where a condition is expected, near 'Select'." And is there a Boolean type in SQL2008? ...

How to copy from a database to a text file using VBScript?

I have an example in C# code, but it is using streamWriter. It must be involving with FileSystemObject rite. If yes, what are methods should I use? I want to code using VBScript WSH, and my database is MS SQL Server 2005. Any solution, references, or guide are helpful. using (StreamWriter tw = File.AppendText("c:\\INMS.txt")) { us...