sql-server-2005

SQL Server 2005 and SQL Server 2008 Coexisting in Windows 7 machine

Some SQL Server 2005 and 2008 questions. 1) Can they coexist on the same Windows 7 machine without issues? 2) Can you attach and run 2005 databases to SQL Server 2008 without compatibility issues or is this a no go? 3) Does SQL Server 2005 even work on Windows 7? ...

Generating scripts for database role membership in SQL Server 2005

I have a database with a lot of users in it. Those users belong to different built-in roles in the DB (eg db_ddladmin). I want to generate a script that creates those same users with the same role assignments to use in a different database. SQL Management Studio seems to only generate sp_addrolemember calls for user-defined roles, not ...

.Net Entity Framework and Transactions

Hi, Being new to the EF, I'm really rather stuck on how to proceed with this set of issues. On the project I am currently working on, the entire site is heavily integrated with the EF model. At first, the access to the EF context was being controlled using an IOC bootstrapper. For operational reasons we were not able to use IOC. I remov...

In SQL Server Management Studio\SQLCMD mode, can I use variables WITHIN a set of statements

Hello, I'm trying to make some of my setup scripts more readable and less prone to error. Here's the type of code I have now in my SQLCMD scripts, which I run from management studio: !!bcp "select * from Database1..Table1 where CreateDate > '7/11/2010'" queryout C:\junk\Table1.tab -n -SServerName1 -UTestUser -PTestPassword !!bcp "sel...

Confused about Itzik Ben-Gan's Logical Query Processing order in his SQL Server 2005 book and SQL Server 2008 book

Hi friends, In the book Inside Microsoft SQL Serverâ„¢ 2005 T-SQL Querying, the author Itzik Ben-Gan tell us the order or SQL Server 2005's logical query processing is: (8) SELECT (9) DISTINCT (11) <TOP_specification> <select_list> (1) FROM <left_table> (3) <join_type> JOIN <right_table> (2) ON <join_condition> (4) WHERE <...

Order of execution in SQL query?

The following query is a contrived example that demonstrates a bug I found in a stored procedure this week. CREATE TABLE #temp ( ID int IDENTITY(1,1), Value char(1) ) INSERT INTO #temp(Value) Values('a') INSERT INTO #temp(Value) Values('b') INSERT INTO #temp(Value) Values('c') INSERT INTO #temp(Value) Values('d') DECLARE @...

What's the best to check if item exist or not: Select Count(ID)OR Exist(...) ?

What's the best in performance to determined if an item exist or not specially if the table contain more than 700,000 row if (Select count(id) from Registeration where email='[email protected]') > 0 print 'Exist' else print 'Not Exist' OR if Exists(Select id from Registeration where email='[email protected]') print 'Exist' else ...

Insert data from one table to another table

Hi, i have on table T1 with data RK1 RK3 RK5 RK2 i want to insert data in table T2 from T1 with output like col1 col2 11 RK1 12 RK2 13 RK3 14 RK5 With col2 sorted? could you please write sql query for the same? ...

ANALYSIS SERVICES in SQL Server 2005

Dear Friend, I want to retrive the Current running value of the Following Analysis Service using SQL Query. Ad Hoc data mining Anonymous connection Linked Objects User Defined Functions Please help me Thank You. ...

SQL Server 2005: Insert multiple rows with single query

Hi all, This should be a fairly straightforward question, but I haven't been able to find a solid answer online. I'm trying to insert multiple rows into the same table, but with only one statement. The most popular I've seen online is the following, but I've read that it only works with SQL Server 2008: INSERT INTO Table (Name, Locatio...

SQL Server 2005: Deleting multiple rows with a single query

This should be a straightforward question, but I haven't found a clear answer yet. Does anyone know how to delete multiple rows from a single table in SQL Server 2005, using a single query? I wondered if it might just be the opposite of inserting multiple rows, using the UNION ALL method. So would this work? : DELETE FROM Table (Name, L...

How do I remove duplicate results from my sql query

Thank you so much for helping! Ok, the portion of my query producing duplicate results is: Left Join CMS_ECH.dbo.hsplit hsplit on hsplit.row_date = ANDREWSTABLE.SegStart_Date and hsplit.split = ANDREWSTABLE.dispsplit and hsplit.starttime = ANDREWSTABLE.Interval ...

SubSonic3 SimpleRepository Relationships Generated are Wrong

I have been told that it's more than likely my database that is setup wrong causing the problems so below are my tables with key fields and queries. CREATE TABLE Presentations ( Id INT NOT NULL IDENTITY(1, 1), SpeakerId INT NOT NULL, CONSTRAINT PK_Presentations PRIMARY KEY (Id), CONSTRAINT FK_Presentations_Speaker FOREI...

How to treat a string as a month in SQL Server

In my database I have a table in which one of the columns is storing joining_months in string format like January, February, March....(and so on). Now I want to run a SQL query on this table to fetch those rows only in which joining month is before or after a user specified month. Something like: select * from table1 where joining_mon...

How to write a stored procedure to return a count of events grouped by 'X' week blocks?

I have a table that records market interactions by employees with customers. Relevant fields would be customerid, date and customer type. I want to be able to get a count of interactions by 5 week blocks going back as far as the between dates that would be submitted by the user and discriminate by customer type a,b,c. I want to be able...

SQL function, extract numbers before -

Hi, i'm playing around with building a sql function that will extract numbers from a title, which is what the following code below does. Although, i want to modify this function to parse numbers into sections. For example: Current Data in title field: QW 1 RT 309-23-1 QW 1 RT 29-1 QW 1 RT 750-1 QW RT 750-1 Temp tables created once f...

SQL Server 2005: Select statement in ISNULL condition

Environment: SQL Server 2005 I have a stored proc which receives comma separated value in one parameter. I have written a Table Valued UDF function in SQL to break it and and return me it as a table. I am using that value to filter the data in the where clause of the stored proc. Everything works fine until there is NULL in that comma s...

Create a table called #test, and create a table called test in the tempdb, what's the difference?

Hi guys, In SQL Server 2005(2008 not tested), you can't create a temp function like #function_name, but you can create a functoin called function_name directly in tempdb. Does the function created in this way a temp function? What's the difference between a table called #table_name and the same named table directly created in tempdb? ...

SQL Server 2005: T-SQL to query when a database was last restored?

Is it possible to do so using T-SQL alone? What query would you write against the system tables? ...

calculating sales, refund and breakages from SQL Server Tables

I have 4 tables namely Products, SalesLog, Breakages, SalesReturn. Products Table CREATE TABLE [dbo].[Products]( [ProductId] [int] IDENTITY(1,1) NOT NULL, [pName] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [pSize] [int] NULL, [pPrice] [decimal](10, 2) NULL, [pPackQty] [int] NULL, [pGroup] [int] NULL, [pCode] [int] NULL, ...