sql-server

SQL Query Advice - Get Previous Customer Order

Hi, I have the following table custid ordid qty datesold 1 A2 12 2008-01-05 2 A5 5 2008-01-02 1 A1 5 2008-01-01 2 A7 3 2007-02-05 What't the best way of getting the previous order for every customer? Thanks ...

Is Guid the best identity datatype for Databases?

It is connected to BI and merging of data from different data sources and would make that process more smooth. And is there an optimal migration strategy from a database without Guids to a version with Guids without information losses? ...

How can I change my default database in SQL Server without using MS SQL Server Management Studio?

I dropped a database from SQL Server, however it turns out that my login was set to use the dropped database as its default. I can connect to SQL Server Management Studio by using the 'options' button in the connection dialog and selecting 'master' as the database to connect to. However when ever I try to do anything in object explorer i...

SQL import wizard drops leading zero

I've read all the posts about prefixing the numbers with ', and setting IMEX=1 in the connection string; nothing seems to do the trick for me. Here's the setup: Excel column with mixed data - 99% numbers (some start with 0) 1% text. PROGRAMATICALLY mporting into SQL Server 2005 table / column type - varchar(255). Import works fine lo...

Possibility to debug from .net code into SQL Server stored procedure code?

Is there any possibility to directly dive into SQL Server stored procedures from .net code? So when debugging step by step in .net, I'd like to step into a called stored procedure. I know how to debug them individually, but I'd like to join these debug sessions in order to gain some time. ...

Use of SET ROWCOUNT in SQL Server - Limiting result set

I have a sql statement that consists of multiple SELECT statements. I want to limit the total number of rows coming back to let's say 1000 rows. I thought that using the SET ROWCOUNT 1000 directive would do this...but it does not. For example: SET ROWCOUNT 1000 select orderId from TableA select name from TableB My initial thought wa...

Browsing for SQL Servers

I'm writing a database application that connects to SQL server. I'd like to implement a similar connection dialog box like the one in SQL Management Studio. I've already found a way to get the list of databases on a server, but I'd really like to get the list of available servers on the network so end users won't have to type in the name...

Possible to setup SQL Managment Studio to show multiline fields when viewing multiline data?

Normally it just puts multiline content on a one liner field and adds slightly smaller than normal tabs between text where the line breaks would normally be. I am using SQL Management Studio Express. ...

Version Agnostic SQL Server Script/Statement that detects existence of a specific database

Due to the packaged nature of the release, a SQL Server script (well more of a statement) needs to be created that can execute correctly on SQL Server 7.0 thru 2008 which can essentially achieve this: if exists(select * from sys.databases where name = 'Blah') Reasons this is difficult. SQL 7 'sys.databases' is not valid SQL 2008 'sys...

SQL Server 2005 - Select top N plus "Other"

I have a table for which I want to select top the 5 rows by some column A. I also want to have a 6th row titled 'Other' which sums the values in column A for all but the top 5 rows. Is there an easy way to do this? I'm starting with: select top 5 columnB, columnA from someTable t order by columnA desc ...

Would you consider using an alternative to MS SQL Server Management Studio?

At work we recently upgraded from Microsoft SQL Server 7 to SQL 2005. The database engine is a lot more advanced, but the management studio is pretty awful in a number of ways. Most of our developers decided they preferred to stick with the old Query Analyzer tool, even though it had a lot of limitations. In my spare time, I decided t...

How can I create a foreign key which references an entire composite key?

I have two tables one has a three column composite key. The other needs to reference this composite key. What is the syntax for creating a foreign key which references multiple columns. I tried googleing, but I couldn't find it. ...

Please critique the design

I want to gather data from different data servers located in Europe and Asia. Rather than running a plain data query task that will clog up the undersea network I am thinking of a couple of machines that will be available for me at the local sites. I am thinking to design the master package so that I can: run remote setup tasks launch...

sp_start_job wait for job to finish

Is there a way to determine when a sql agent job as finished once it has been started with sp_start_job? ...

Microsoft (SQL) server licensing

We're planning a browser application (xbap) which is going to talk to WCF services. These WCF services get information from a SQL database. Each of our clients has his own database on this server. The clients need to get reports from SQL Reporting Services. A client can have multiple instances of this application running. How does this ...

PDF generation

We currently send an email notification in plain text or html format. Our environment is C#/.NET/SQL Server. I'd like to know if anyone recommends a particular solution. I see two ways of doing this: dynamically convert current email to pdf using a third party library and sending the pdf as an attachment or use SSRS to allow us...

Why isn't SSAS loading any measure data for my cube?

Background: I'm writing a data provider that SSAS will use to get data from a third-party system. I wrote a tool that will build cubes, dimensions, measure groups and measures based on the configuration of the third-party system using AMO. Now, in the Cube Browser, I am able to pull the members of the dimensions, however, measure data ...

BULK IMPORT a zip file in T-SQL

I've got some data files that are stored compressed on our company's server with a .Z extension (UNIX compress utility used to zip them down). Can SQL Server's BULK IMPORT operation read these files in that format? Or must I uncompress them before getting at the data? ...

Getting login failed for sa when I haven't changed the password

I've been developing a winforms app tied to sql server. I haven't rebooted in a while. Today i rebooted and now I can't log into sql. I used every account I know and their passwords including one that was working just before i rebooted and i get a 'Login failed' . I did take the database I use offline just before starting and I do have b...

Is the Sql Server Unique Key also an Index?

Hi folks, I've got a column in a table (eg. UserName) which I want to make sure is unique. So I create a unique key for that column and call it IX_Users_UserName. Now, if I do lots of searching for users based on their username I want to make sure there is an index for that field. Do I need to create a separate index, or is the unique...