sql-server

Database Schema for Hierarchy

I am looking for a generic open source database schema for a basic login, and user management with roles. Users: belong to Business Units which belong to Clients. Users have Roles - Manager, Regional Manager, site manager, worker etc. Users can have multiple roles dependant on the business unit and multiple business units.. Business ...

SQL SERVER Project

My Application Database Without Project and without Source safe, i planned to make my DB to be as project and add it to TFS, but I have no idea how to script the stored procedures, Triggers, Views, Functions, and what is the best practice to Make Update Script for All My stored procedures, Triggers, Views, and Functions to My customers D...

My publisher failed now I have orphaned subscriptions, what now?

Ok, I am just trying to get a place to start here. My sql 2005 publisher with one sql 2000 subscription and one sql 2005 subscription has died. They are trying to rebuild the thing but it is taking too long. I need to synch the two subscribers and make one the publisher(sql 2005 box of course). Isn't there some tables that keep a his...

T-SQL: IN statement in result Expression in CASE THEN expression

Is it possible to use IN in CASE..THEN ? WHERE record.field = CASE WHEN @flag = 1 THEN a WHEN @flag = 2 THEN IN (b, c) END Or how to rewrite such condition? ...

Why does Mercurial think my SQL files are binary?

I just scripted out my SQL Server stored procs, table definitions, etc using SQL Server Management Studio, and tried to add them to my Mercurial source control repository. They got added just fine, but now when I change and diff them, Mercurial calls them "binary files" and doesn't give me a proper unified diff. I thought the encoding ...

Transact SQL: selecting a boolean expression

Query: SELECT TOP 1 ReportInvoked , EmailSent FROM tblReportInvoker WHERE WebUserId = 12345 This gives me two bit values. What I really want is a scalar result that is the logical AND of these two values. Is this possible? This seems like it would be easy but I'm not finding a syntax that will work. Edit: Of course the flaw in my...

Batch processing with Windows Workflow

Can anybody please provide any links and/or recommendations for the processing of batch information with Windows Workflow. Specifically, I am looking at an invoicing scenario where there are complex rules required for the generation of prices and I am looking to be able to read in excess of 50k rows of data from a SQL Server 2008 databa...

Recursive Query - Only select nodes where leaf nodes represent active data

Given the following recursive query: WITH DepartmentHierarchy (DepartmentID, Name, IsInactive, IsSpecial, ParentId, HierarchyLevel) AS ( -- Base case SELECT DepartmentId, Name, IsInactive, IsSpecial, ParentId, 1 as HierarchyLevel FROM StoreDepartment WHERE ParentId IS NULL UNION ALL ...

Join query result to a single line of values separated by comma

Possible Duplicate: SQL Server: Can I Comma Delimit Multiple Rows Into One Column? I have a query like this: SELECT name from users and it's result is a number of records: 1 user1 2 user2 3 user3 I want to get all this records in a single line separated by comma: user1, user2, user3 and an empty line if query result i...

Sql server table can be queried but not updated

i have a table which was always updatable before, but then suddenly i can no longer update the any of the columns in the table. i can still query the whole table and the results come back very fast, but the moment i try to update a column in the table, the update query simply stalls and does nothing. i tried using select req_transact...

MS SQL: One Large, Multi-Column dbo.Person table or Multiple Subsets With Multiple Joins?

Hi, I am thinking through the layout of my "Person" table in my MSSQL DB. Is it better to have all columns in dbo.Person as such: Person ( personid first last email confirmcode isconfirmed homeaddress homecity homestate homezip session ipaddress workaddress workcity workstate workzip etc... ) OR, is it better to partition the tabl...

MS-SQL Average Columns with NULL

So I've got 3 different columns (basket 1, 2, and 3). Sometimes these columns have all the information and sometimes one or two of them are null. I have another column that I'm going to average these values into and save. Is there a sleek/easy way to get the average of these three columns even if one of them is null? Or do I have to hav...

Inner Joining two tables based on all "Key/Value" Pairs matching exactly

Lets say I have two tables - Person and Clothes and both of these tables have associated Key/Value tables which store attributes about a Person and an item of Clothing. A joined version of Person to Attributes might look like: PersonID | AttributeKey | AttributeValue 1 'Age' '20' 1 'Size' 'La...

How to show a column value which has XML file in webbrowser - C#?

I have table which stores entire XML file in a column. I want to show that column's stored value (ie. XML ) in web-browser using C#. Please help/suggest some way to implement this. The trick is to retrieve the column and need to be displayed in webbrowser control. Please suggest. Thanks, Karthick ...

Listing rights/roles on MS SQL Server 2005 and Analysis Services using Perl (or PHP)

As part of a project to create a tool to query all sorts of permissions relevant to users in our area at work, I need to query some information about our database servers. The servers run SQL Server 2005 (including instances of Analysis Services 2005). I need to be able to find for a given server: The list of logins on that server The...

Importing data from Access to SQL Server (with minor table changes)

I'm currently working on migrating an application from MS-Access to MS SQL Server. In the process, there are a few minor changes that I am making to the table layouts (I am splitting a few things up into more two tables), however, I would still like to keep all the data that is present in the database. What would be the best way to imp...

SQL : Error converting data type varchar to numeric

I have met a very strange problem. There are two sql queries: Q1: SELECT * FROM tbl_1 WHERE ID IN (SELECT TargetID FROM tbl_2 WHERE PeopleID = 'AAA') AND ID = 49 Q2: SELECT * FROM tbl_1 WHERE ID IN (SELECT TargetID FROM tbl_2 WHERE PeopleID = 'BBB') AND ID = 49 We could find ...

SQL CLR - Does lock statement make any difference?

Hello All, I have written the following piece of code ( sql clr stored procedure ) that writes messages to a local file. The problem occurs when multiple connections call the stored proc at the same time. So I used a lock statement. But this doesn't seem to make any difference? What am I doing wrong here? lock (SqlContext.Pipe) { S...

How to add Stored Procedures to Version Control

Our team just experienced for the first time the hassle of not having version control for our DB. How can we add stored procedures at the very least to version control? The current system we're developing relies on SPs mainly. ...

What is the usage of Execution Plan in SQL Server?

What is the usage of Execution Plan in SQL Server? When can these plans help me? ...