sql-server-2008

How can i use a min() funct in this sql query?

UPDATE MRT SET Date = MR.Date FROM MRT JOIN MR on MR.SKU = MRT.SKU HERE Is where i would like to do an order by min(mr.Date) All I get is an incorrect Syntax error. I have to set the date = the smallest mr.date ...

Tools to convert database tables to c# classes

Is there any free tool or plug-in for Visual Studio to convert the SQL tables to entity,model,facade and DAO classes? I am working on SQL server 2008, Visual Studio 2008 and C#. ...

Why does the parameterized version of this query run slower than a non-parameterized version?

Sample Query: CREATE PROCEDURE dbo.Test (@p varchar(10)) AS DECLARE @param varchar(10) SET @param = @p + '%' SELECT * FROM table1 t1 INNER JOIN table2 t2 on t1.id = tr.id WHERE t2.desc LIKE @param I've a query which is similar to one above and when i use this in stored procedure it runs indefinitely without giving any output. But if ...

The Best Way For Transfer Data From One DataBase (sql server 2008) To Another db(sql server 2008) With Different Schema....

hi my dear friends : what is the best way For Transfer Data From One DataBase (sql server 2008) To Another db(sql server 2008) With Different Schema? is there a program for doing that ? thanks 4 your future asnwer best regards ...

Replace NOT working!!!

I have column with values that have wrong character ?. Now I want to change it to character b. For this I am using this statement: SELECT REPLACE(name,'?','b') from contacts; But when I do this nothing's happening, it return value with ?. What I am doing wrong? How I can replace this? ...

Sql server 2008 - performance tuning features for insert large amount of data.

Hi, I have to insert large amount of data into a table. Does sqlserver 2008(compared to 2005) has any new features to increase the performance in this case ? ...

Has date type changed in SQL Server 2008?

I am confused reading statements in "Why is 1899-12-30 the zero date in Access / SQL Server instead of 12/31?" Was there date type in SQL Server before 2008 version? I cannot find. In SQL Server 2008 zero date is 0001-01-01. Were there any date type before (in previous SQL Server versions) how is it backward compatible? ...

Can we use Sql server 2008 newly added features in Sql management studio 2005?

Declare @strxml varchar(max) = '' This is the newly added feature in sql server 2008 which allows us to initialize the variables at declaration itself. When I'm executing these commands in sql management studio 2005 I'm getting aN error message. "Cannot assign a default value to a local variable." ...

Which DAL libraries support stored procedure execution and results materialisation

I'm used to EF because it usually works just fine as long as you get to know it better, so you know how to optimize your queries. But. What would you choose when you know you'll be working with large quantities of data? I know I wouldn't want to use EF in the first place and cripple my application. I would write highly optimised stored ...

SQL SELECT Query for a Total and parts building the total

Hello! I need a SQL Server Query for the following scenario: The Tables: CREATE TABLE [dbo].[JobStatus] ( [OID] [int] IDENTITY(1, 1) NOT NULL, [Name] [varchar](100) NOT NULL, [Code] [varchar](5) NOT NULL, [PictureID] [int] NOT NULL, [LastModifiedAt] [timestamp] NOT NULL, CONSTRAINT [PK_JobStatuses]...

Why insert-select to variable table from XML variable so slow?

Hi I'm trying to insert some data from a XML document into a variable table. What blows my mind is that the same select-into (bulk) runs in no time while insert-select takes ages and holds SQL server process accountable for 100% CPU usage while the query executes. I took a look at the execution plan and INDEED there's a difference. The...

How to insert into tempoary table twice

I've picked up some SQL similar to the following: IF EXISTS(SELECT name FROM tempdb..sysobjects WHERE name Like N'#tmp%' and id=object_id('tempdb..#tmp')) DROP TABLE #tmp into #tmp select * from permTable I need to add more data to #tmp before continuing processing: insert into #tmp select * from permTable2 But this gives errors ...

variable decimal places in sql

How do you make it so that all calculations in the DB compute to a pre-specified # of decimal places? Say I have three tables with the following fields Table1 A int B decimal(18, 3) Table2 A int B decimal (18, 2) C decimal (18, 3) Table3 A int Precision int Now I need to change it so that all my calculations are based on w...

sql server conditional select into temp table

I'm working in SQL Server 2008, and I'm trying to select into a temp table based on a certain condition...for a report, I need up to 18% of the records to be of a certain product type. if ((@totalRecords * .18) > @productTypeCount) select * into #tmpLP_REIT from myTable where productType = @productType else select top 18 per...

SQL Server 2008: I have 1000 tables, I need to know which tables have data

Is there a way in SMSS to detect whether a table has any records? I need to get a list of tables that have records. perhaps there is a sql statement that will do the trick? ...

how to find contactid in sql server ?

RCustomerId GiftRegistryId ContactId DateActive DateExpire ----------- -------------- --------- ---------- ---------- 62 66 225 NULL 2010-10-11 62 66 228 2010-10-13 NULL 62 67 229 NULL 2010-10-20 62 ...

Does it make sense to optimize queries for less i/o pressure?

I have a read only database (product) that recides on its own Sql Server 2008. I already optimized queries by looking at most expensive queries in activity monitor - report. I ordered the report by CPU-cost. I now have something like 50 queries/second and no query is longer than 300ms. CPU-Time is ok (30%) and Memory is only used by 20...

Auditing a terribly designed database system in SQL 2000

One of the most important databases that I administer is poorly designed. The program which uses it uses only 1 login which happens to be a System Administrator. Edits and deletes are done in place so change tracking is difficult. Further, it lacks proper auditing functionality so I cannot tell which user edited or deleted a certain re...

Need reference code for SMO in C# SQL Server 2008

I googled but cannot find proper simple code for using backup database full and restore the backup, using defaults by using C#. I am using C# Visual Studio 2008 and SQL Server 2008 R2 evalution but I guess SQL Server 2005 and C# will work too. The Microsoft site doesn't have code regarding it, it only show description of Microsoft.SqlS...

Who should be an owner of the new schema?

I am creating a new schema in SQLServer 2008. Should I create a new user with the same name as schema owner? Should I use 'dbo' user as schema owner? ...