sql-server

Distribute OLAP cubes as part of application setup

We currently have our custom application that is being distributed with our database (SQL 2005/2008). It is an easy task, before we release a new version we just pack our database into SQL initialization scripts (these create tables and populate data). We use SQL Management studio to generate these scripts. As a next step we would like ...

Select Same Customer Name but that has different customer Address

Trying to select records that are all for the same customer, but where the address is different. So I can later let the user choose Bob Yonkers, then choose to update all of Bob's records to a specific address. So I want to show all the available records. Data Example: CUSTOMER_NAME, CUSTOMER_ADDRESS Bob Yonkers , 42 Satellite Cir ...

Best approach for integrating data between two SQL databases?

Hello, I am writing an events calendar, and the data for the calendar I will need to pull from another database and make some changes to before committing to mine. What are some basic approaches for this that you would suggest? This data is not super sensitive or in need of enterprise solution. I am thinking of writing a service whic...

Rewrite T-SQL from using IN to using JOIN/WHERE

How can I rewrite this t-sql to avoid using IN - and use joins in stead? --Members with membership in 2008 but not in 2009, using IN and NOT IN SELECT * FROM @Members WHERE MemberId NOT IN (SELECT MemberId FROM @Memberships WHERE [Year] = 2009) AND MemberId IN (SELECT MemberId FROM @Memberships WHERE [Year] = 2008 ) I want to fi...

t-sql udf, get the data type of a parameter

is it possible to get a numeric parameter to my udf and do stuff according to its type, like: if type of @p1 is decimal(10,3) ... else if type of @p1 is decimal(15,3) ... else if type of @p1 is integer ... ...

NHibernate Many to many mapping with additional columns in the mapping table

There are two tables Person and Address. I have a mapping table PersonAddressMap which contains an additional column IsCurrent other than the two foreign keys (no explicit primary key column). I have created three mapping classes one each for Person, Address and PersonAddressMap. I need to access all the Addresses of a Person and also ac...

SQL Merge Replication: How to tell if a record has been replicated

I have a merge replication scenario, with SQL2005 SP3 as the publisher and distributor and windows mobile SQLCE 3.5 SP1 as the subscribers. The replication filter is such that rows from one of the tables (tblJobs) only go to exactly one device. After the device has replicated it executes sql to set the IsSynced boolean column on all th...

Severe error when trying to FREETEXTTABLE an indexed view with a CTE

Hi, Where stockView is an indexed view with a full-text index, I receive the error message below. The database is running on a 2008 Express engine in 2005 compatibility mode. Code: with stockCte (title, grade, price, weighted) as ( select sv.[title] , sv.[grade] , sv.[price] , (case when sv.[issue] = ...

c# .net reporting services dynamically create optional footer for .rdlc report

I already searched for this and I did not find the answer I was looking for. I am writing a windows forms program with C# .NET and Visual Studio 2008. I am using Reporting Services and rendering the reports using the .net provided report viewer. The data source for the reports is SQL Server. I am rendering the reports locally. I am ...

How to return result of Sql Server stored procedure to .Net

What is the best way to return the result of the execution of a SQL Server stored procedure back to the .NET code? If I want to return the success or failure of a bunch of deletes in a transaction, should I 'Select' something, or maybe something like RETURN(1) or RETURN(0), or do I communicate number of rows affected? Then will this be...

Why does the following SQL Server insert deadlock when run within a transaction?

I'm currently inserting a record into a SQL Server Table and then selecting the auto-increment ID as follows: (@p0 int,@p1 nvarchar(8))INSERT INTO [dbo].[Tag]([Some_Int], [Tag]) VALUES (@p0, @p1) SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value] (This was generated using Linq-to-SQL). For some reason when I run this code inside a trans...

differences between two SQL Server database snapshots

I am trying to automate order processing for a client their POS vendor doesn't have any sort of API with their software so I was hoping to be able to insert orders directly in the database. so what i want to do is take a snapshot of the database, enter an order manually and then take another snapshot and compare the 2 snapshots to see w...

SQL Server: Output an XML field as tabular data using a stored procedure

I am using a table with an XML data field to store the audit trails of all other tables in the database. That means the same XML field has various XML information. For example my table has two records with XML data like this: 1st record: <client> <name>xyz</name> <ssn>432-54-4231</ssn> </client> 2nd record: <emp> <name>abc</...

sql server udf, return the same type as the input expression

is it possible for a udf to return the same data type as one of its parameters? i would like my udf to accept a decimal of any precision and scale and return the same type. ...

Error handling and data integrity when changing table schema

We have a few customers with large data sets and during our upgrade procedure we need to modify the schema of various tables (adding some columns, renaming others, occasionally changing data types, but that's rare). Previously we've been going via a temporary table with the new schema, and then dropping the original and renaming the tem...

SQL Server Full Text Search Escape Characters ?

I am doing a MS SQL Server Full Text Search query. I need to escape special characters so I can search on a specific term that contains special characters. Is there a built-in function to escape a full text search string ? If not, how would you do it ? ...

SET NOCOUNT OFF or RETURN @@ROWCOUNT?

I am creating a stored procedure in Sql Server 2008 database. I want to return the number of rows affected. Which is a better option SET NOCOUNT OFF or RETURN @@ROWCOUNT? ALTER PROCEDURE [dbo].[MembersActivateAccount] @MemberId uniqueidentifier AS BEGIN -- Should I use this? SET NOCOUNT OFF; UPDATE [dbo].Members SET acc...

Entities and Dynamic Data Site: references between tables.

I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT NULL, [Naam] nvarchar (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [Code] nvarchar (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [Omschrijving] ntext COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ; ALTER TABLE [dbo].[Context] A...

How can I set the IDENTITY_INSERT option for a JDBC PreparedStatement?

I need to copy data into an MSSQLServer 2005 database table which has an identity column. I've seen how to disable the identity column by executing SET IDENTITY_INSERT <table> ON before the insert queries. How can I do this when I'm using PreparedStatements to do batch inserts and I can't change the statement during the operation? ...

Passing an array of values to a stored procedure in SQL 2005

Does T-SQL accomodate for array values as parameters for stored procedures? If so how can this be achieved. ...