sql-server-2008

Is there anyway to reference the collection of parameters passed to a stored procedure, without referencing each one by name?

Is there any way to reference the collection of parameters passed to a stored proc, without referencing each one by name? The context here is error logging. I'd like to develop a generic CATCH clause, or sub-clause, that grabs all parameter values as well as other error and execution info and logs it to a table (one or more). The basic...

SQL Server: how to query when and where (which database) logins take a connection?

I have many databases in one SQL Server instance. Also I have many individual domain users for logins and also domain groups as logins. These logins are attached to databases as database users. Now I would like to create a report (or a query) to find out when and where (which database) these logins take a connection. I tried to find this...

How to add a new identity column to a table in SQL Server?

Hello everyone, I am using SQL Server 2008 Enterprise. I want to add an identity column (as unique clustered index and primary key) to an existing table. Integer based auto-increasing by 1 identity column is ok. Any solutions? BTW: my most confusion is for existing rows, how to automatically fill-in new identity column data? thanks in...

Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.

I'm currently setting up my website on a new SQL Server 2008 server, however I'm getting the following error: Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately....

How do I run several .sql scripts from one query?

In SQL Server Management Studio, I want to execute a number of SQL scripts (saved queries) one after the other. This is simply to make it easier to run each. I could take each script and combine them all into one massive script and simply execute the lot, however I want it to all be separate so I can easily and simply run each bit by bit...

Parse XML To build Dynamic Query

Hi All, I am trying to figure out the best way to handle a scenario where I will be passed XML that will contain criteria for a search. If the user has selected specific filters then those will be sent in the XML and if there is a section that they left unfiltered then it will not be present in the XML (Which would mean everything for ...

In Sql server, when should you use GO and when should you use semi-colon ; ?

I've always been confused with when I should use the GO keyword after commands and whether a semi-colon is required at the end of commands. When I run the Generate-script in sql server management studio, it seems to use GO all over the place, but not the semi-colon. Please can someone explain to me the differences and why/when i should...

Easy method to remove unnecessary tables/dependencies from a large complex join.

I have a large complex set of joins in an sql statement (roughly getting 250 fields and using about 80 joins). I would like to split this large cumbersome query into some smaller ones, say returning only 10 fields each. However, the task of removing all of the joins (which are unnecessary for those 10 fields) is massively time consuming...

Move Model Database (How to change default database location)

I'm not sure if this would belong on Stack Overflow or Server Fault, so if it belongs on Server Fault please let me know. Anyway, here's the problem. I've got an install of SQL Server 2008 on a server on the local c drive. The c drive is not a large drive, and as such i want all new databases created on the server to be created on the...

SQL Server Compare similar tables with query

Simple concept we are basically doing some auditing, comparing what came in, and what actually happened during processing. I am looking for a better way to execute a query that can do side by side table comparisons with columns that are slightly differnt in name and potentialy type. DB Layout: Table (* is the join condition) Log (Un-a...

MS-Access front-end does not recognise dates from SQL Server

I have a SQL Server 2008 database with an Access front-end. My problem is that Access does not recognise SQL Server's dates as they are in a different format. SQL Server-s format is YYYY-MM-DD Access' format is DD-MM-YYYY When the date is displayed in a text-box, it is displayed as a string (without the little calendar icon next to it)...

DMV in SQL 2008 to replace dm_os_exec_requests

I've been going through an old SQL 2005 performance tuning document and it talks about the dynamic management view sys.dm_os_exec_requests. It looks like that view is no longer available in SQL 2008. Is there a direct replacement? Is there a standard way of selecting the same data from another DMV or group of DMVs? Thanks! ...

How to implement reverse geocoding on SQL Server 2008 (with spatial capabilities)?

Let's suppose I have a street shapefile loaded on SQL Server 2008. How can I implement a reverse geocode function (get an address from a lat/long pair)? What SQL Spatial functions can I use for that? Does it have a function that get the closest "feature" from a lat/long pair? ...

Fastest way to map a list of names in an excel doc to their IDs in a lookup table?

For one of my projects I display a list of counties in a drop down list (this list comes from a lookup table containing all counties). The client just requested that I limit it to a subset of their choice. The subset was given to me in an excel spreadsheet containing only names (seen below): I'm trying to figure out the quickest way...

Help with TSQL join query

Based on below 2 tables declare @t1 table ( Id int, Title varchar(100), RelatedId int ) insert into @t1 values(1,'A',2) insert into @t1 values(1,'A',3) declare @t2 table ( Id int, Title varchar(100) ) insert into @t2 values (2,'B'), (3,'C') I am trying to get the below output Id Title RelatedItems -------...

How to reference embedded SQL Server Reporting Service 2008 images

I have a SQL Server 2008 report with a bit field - IsUS I'd like to display embedded images depending on IsUS bit value. How can I reference embedded images within a column expression? Below is the result after applying Fillet's answer -------------------- Result -------------------- ...

Handling IS NULL inside string in SQL

I have a SQL query which is written in string and then executed using command Exec(string) like the following : Declare @TestId bigint = null Declare @Query nvarchar(max) set @Query = 'SELECT * from Registrations where RegistrationId = 15 AND (' + CAST(@TestId AS NVARCHAR) + ' IS NULL OR TestId = ' + CAST(@TestId AS NVARCHAR) + ') ' EXE...

JDBC not seeing updated table structure

I am using Coldfusion 8 which is connecting to SQL Server 2008, the problem is I have updated a table adding a new column in SSMS, but the JDBC connection is still 'seeing' the table prior to the change. How can I essentially 'refresh' the JDBC connection? Would restarting the cf server work? ...

ssis merge join more than 2 data sets

I'm working on an ssis package to fix some data from a table. The table looks something like this: CustID FieldID INT_VAL DEC_VAL VARCHAR_VAL DATE_VAL 1 1 23 1 2 500.0 1 3 David 1 4 4/1/05 1 5 52369871 2 1 25 2 2 ...

How can we set tables relations in SQL Server Express?

I have SQL Server Express 2008. How can I set a table's relations in it? ...