sql-server

How do I get an stored procedure output into a variable inside a function in T-SQL?

I've got a task which can be only accomplished by construction a QUERY at runtime and executing it with sp_executesql. The result has to be a boolean (0/1 integer) value which I need to return as a result of the function. The only way I found to capture an SP's output is "INSERT INTO [table] EXECUTE [sp]" query, but functions forbid thi...

SQL Server 2008 Insert performance issue

is there any way to increase performance of SQL server inserts, as you can see below i have used below sql 2005, 2008 and oracle. i am moving data from ORACLe to SQL. while inserting data to SQL i am using a procedure. insert to Oracles is very fast in compare to SQL, is there any way increase performance. or a better way to move data ...

Modeling many-to-one with constraints?

I'm attempting to create a database model for movie classifications, where each movie could have a single classification from each of one of multiple rating systems (e.g. BBFC, MPAA). This is the current design, with all implied PKs and FKs: TABLE Movie ( MovieId INT -- PK ) TABLE ClassificationSystem ( ClassificationSystem...

Prepare and import data into existing database

I maintain a PHP application with SQL Server backend. The DB structure is roughly this: lot === lot_id (pk, identify) lot_code building ======== buildin_id (pk, identity) lot_id (fk) inspection ========== inspection_id (pk, identify) building_id (fk) date inspector result The database already has lots and buildings and I need to ...

SQL Server, varchar data to nvarchar data

I've got a database with collation Danish_Norwegian_CS_AS and lots of varchar columns. I'd like to convert all this data to unicode, but haven't found a way to convert this data yet. If I've understood correctly, the encoding used is UCS-2 little endian. For example I've got a column containing 'PÃ¥l-Trygve' which is easily converted w...

MIME type of SQL Server Database BACKUP file

I am not able to find an answer to this. Does anybody know this? I want to enable the download of .bak file and for that I need to know the mime type so that i configure the same in the IIS for .bak file. Any help is appreciated. ...

using NEWSEQUENTIALID() with UPDATE Trigger

I am adding a new GUID/Uniqueidentifier column to my table. ALTER TABLE table_name ADD VersionNumber UNIQUEIDENTIFIER UNIQUE NOT NULL DEFAULT NEWSEQUENTIALID() GO And when ever a record is updated in the table, I would want to update this column "VersionNumber". So I create a new trigger CREATE TRIGGER [DBO].[TR_TABLE_NAMWE] ON [DBO]...

Copying a subset of data to an empty database with the same schema

I would like to export part of a database full of data to an empty database. Both databases has the same schema. I want to maintain referential integrity. To simplify my cases it is like this: MainTable has the following fields: 1) MainID integer PK 2) Description varchar(50) 3) ForeignKey integer FK to MainID of SecondaryTable Second...

Centralizing / abstracting SQL Server data from multiple tables / databases

If one has a number of databases (due to separate application front-ends) that provide a complete picture - for example a CRM, accounting, and product database - what methods are available to centralize/abstract this data for easy reporting? Essentially, I'm wondering if there is a way to automatically pull data from multiple databases ...

SQL Server: how to export a table

how can I export a SQL Server table to Mysql ? I guess I need to export a .sql file compatible... thanks ...

TSQL ID generation

Hi. I have a question regarding locking in TSQL. Suppose I have a the following table: A(int id, varchar name) where id is the primary key, but is NOT an identity column. I want to use the following pseudocode to insert a value into this table: lock (A) uniqueID = GenerateUniqueID() insert into A values (uniqueID, somename) u...

selectively execute task in ssis control flow

I have a SSIS package with a control flow containing a bunch of execute sql tasks in a sequence. I need to check a flag for each of the tasks and run the task if it is set, if not skip and go to the next one. Each of the these task executes a stored proc. So i can check in the proc and "Return" if not set. I was looking for a "SSIS" s...

How to add "missing" columns in a column group in reporting services?

Hello, I'm trying to create a report that displays for each months of the year the quantity of goods sold. I have a query that returns the list of goods sold for each month, it looks something like this : SELECT Seller.FirstName, Seller.LastName, SellingHistory.Month, SUM(SellingHistory.QuantitySold) FROM SellingHistory JOIN Seller o...

I want to search in SQL Server with must have parameter in one colunm

hello I am using c# and SQL Server 2008. I have table like this id | propertyTypeId | FinishingQualityId | title | Description | features 1 1 2 prop1 propDEsc1 1,3,5,7 2 2 3 prop2 propDEsc2 1,3 3 6 ...

SQL Server 2008 - Get Latest Record from Joined Table

Hello, I have a SQL Server 2008 database. This database has two tables called Customer and Order. These tables are defined as follows: Customer -------- ID, First Name, Last Name Order ----- ID, CustomerID, Date, Description I am trying to write a query that returns all of the customers in my database. If the user has placed at leas...

Database per application VS One big database for all applications

Hello, I'm designing a few applications that will share 2 or 3 database tables and all of the other tables will be independent of each app. The shared databases contain mostly user information, and there might occur the case where other tables need to be shared, but that's my instinct speaking. I'm leaning over the one database for all...

SQL Server / T-SQL : How to update equal percentages of a resultset?

I need a way to take a resultset of KeyIDs and divide it up as equally as possible and update records differently for each division based on the KeyIDs. In other words, there is SELECT KeyID FROM TableA WHERE (some criteria exists) I want to update TableA 3 different ways by 3 equal portions of KeyIDs. UPDATE TableA SET FieldA...

SQL Server 2005 Users & Roles

All, I am trying to script out a database in SQL Server Management Studio 2005. In my database users belong to different roles. Unfortunately I can't find how to script out the relationship between users and roles. Thanks, M ...

Storing unicode strings to SQL Server via ActiveRecord

I am using Castle ActiveRecord as my ORM. When I try to store unicode strings, I get question marks instead. Saving unicode strings worked perfectly when I was using mysql, but when I recently switch to SQL Server it broke. How should I go about fixing this? ...

What is the most effective and flexible way to generate combinations in TSQL?

What is the most effective and flexible way to generate combinations in TSQL? With 'Flexible', I mean you should be able to add easily combination rules. e.g.: to generate combinatories of 'n' elements, sorting, remove duplicates, get combinatories where each prize belongs to a different lottery, etc. For example, Having a set of number...