sql-server

SQL Profiler and Tuning Advisor for Reporting Services - what events should be selected?

I've used the SQL Profiler to generate a trace file, and tuning advisor to take that trace file and provide some recommendations on db updates. However, the SQL Profiler doesn't seem to track the queries when running against a Reporting Server, the profiler doesn't seem to be capturing any of the queries. I'm logging the defaults (SQL:...

Is there anyway that we can get a label value to a Sql

SELECT COUNT(*) AS Expr1 FROM Book INNER JOIN Temp_Order ON Book.Book_ID = Temp_Order.Book_ID WHERE (Temp_Order.User_ID = 25) AND (CONVERT (nvarchar, Temp_Order.OrderDate, 111) = CONVERT (nvarchar, GETDATE(), 111)) In here i want to change my User_ID to get from a label.Text this Sql Statement is in a DataView. so in the Wizard it...

Which SQL query is faster? Filter on Join criteria or Where clause?

Compare these 2 queries. Is it faster to put the filter on the join criteria or in the were clause. I have always felt that it is faster on the join criteria because it reduces the result set at the soonest possible moment, but I don't know for sure. I'm going to build some tests to see, but I also wanted to get opinions on which would ...

Fully automated SQL Server Restore

I'm not very fluent with SQL Server commands. I need a script to restore a database from a .bak file and move the logical_data and logical_log files to a specific path. I can do: restore filelistonly from disk='D:\backups\my_backup.bak' This will give me a result set with a column LogicalName, next I need to use the logical names fr...

SQL Server: String Manipulation, Unpivoting

I have a column called body, which contains body content for our CMS. The data looks like: ...{cloak:id=1.1.1}...{cloak}...{cloak:id=1.1.2}...{cloak}...{cloak:id=1.1.3}...{cloak}... A moderately tweaked for readability example: ## h5. A formal process for approving and testing all external network connections and changes to the f...

nested insert exec work around

I have 2 stored procedures usp_SP1 and usp_SP2. Both of them make use of insert into #tt exec sp_somesp. I wanted to create a 3rd stored procedure which will decide which stored proc to call. Something like: create proc usp_Decision ( @value int ) as begin if (@value = 1) exec usp_SP1 -- this proc already has insert into #tt...

Sum of XML duration elements in SQL2008

I have a XML column that holds information about my games. Here's a sample of the information looks like. <game xmlns="http://my.name.space" > <move> <player>PlayerA</player> <start movetype="Move">EE5</start> <end movetype="Move">DF6</end> <movetime>PT1S</movetime> </move> <move> <player>PlayerB</player> <start ...

Count for consecutive records

I have a table as follows > RowID SessionID EventID RequestedURL Date > 1 m2jqyc45g 1 Start 24/03/2010 19:52 > 2 m2jqyc45g 1 ProductPage 24/03/2010 19:52 > 3 m2jqyc45g 28 BuyNow 24/03/2010 19:52 > 4 tjmvb55dc4dg 1 ProductPage 24/03...

Database schema last updated date.

How to find out the last date and timestamp of schema updation in SQL Server database. I could locate the database created and last back up date from properties. But, couldn't find the last schema updated date. Is there a way to find this out? ...

SQL Server "RESTORE FILELISTONLY" Resultset

I'm trying to write an automated backup and restore T-SQL scripts. I've done BACKUP part but I'm struggling on RESTORE. When I run following statement on SS Management Studio; EXEC('RESTORE FILELISTONLY FROM DISK = ''C:\backup.bak''') I get a result set in a grid and also I can use INSERT INTO <temp_table> EXEC('RESTORE FILELISTO...

Asp.net mvc - trying to display images pulled from db \

//Inherits="System.Web.Mvc.ViewPage<FilmFestWeb.Models.ListVideosViewModel>" <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>ListVideos</h2> <% foreach(BusinessObjects.Video vid in Model.VideoList){%> <div class="videoBox"> <%= Html.Encode(vid.Name) %> <img src="<%= ...

What's an efficient way to convert month and year string to a date?

I have column with varchar values like "022008" that I need to convert into a datetime like "02/01/2008". This will run on millions of records for a conversion process. What is an efficient select statement for doing this? ...

Like operator in sql server

I want to get all the record from the one table which contain atleast one word from the input string. Ex: input parameter='Stack over flow': select * from sample where name like '%stack%' or name like '%over%' or name like '%flow%' I want to search record which contains 'stack' or ' over' or 'flow' ... ...

Sql Server - INSERT INTO SELECT to avoid duplicates

I have following two tables:- Table1 ------------- ID Name 1 A 2 B 3 C Table2 -------- ID Name 1 Z I need to insert data from Table1 to Table2 and I can use following sytax for the same:- INSERT INTO Table2(Id, Name) SELECT Id, Name FROM Table1 However, In my case duplicate Ids might exist in Table2 (In my case Its Just "1") ...

Remote connect to SQL server - trusted connection, windows credentials

Hi, Sorry for the confusing name, I did not know of better one. There is a network with SQL 2005 server. I am provided with the windows account information to this computer so I can use remote desktop or map its drives. The SQL uses trusted connection. I am thinking whether I can connect remotely only to the SQL server? Thanks ...

how to take a backup from server database ?

I have connected to local and server database from local SqlServer 2005. How to take a backup from server database ? Regards, kumar ...

Getting sourcecontrol on stored procedures

First off the technical stuff: We're using VS 2008 pro and running a MS SQL 2008 server. For sourcecontrol we use Subversion. We'd really like to keep our stored procedures in subversion, so we can tell what was changed, when and so forth. However in order for this to work, it has to be seamless, otherwise the developers are just goin...

Crash trying to migrate MySQL DB to SQL Server w/SQL Server Import Export Wizard

I'm trying to migrate a MySQL DB to SQL Server using MS's SQL Server Import Export Wizard. It isn't going so well... The wizard either tells me that the MySQL syntax is invalid or crashes depending on its mood. Here is the query that it executes against MySQL before failing: select * from "_account" Anyway to change so either MySQL l...

LINQ2SQL and SQL Server 2000

Good day! I have used LINQ2SQL with SQL Server 2005, but now I need to use it with SQL Server 2000. I have found only article on MSDN that tells about Skip() and Take() oddities on SQL Server 2000 (that's because it lacks ROW_NUMBER(), I suppose) and nothing more. Anyway, does anybody have experience with LINQ2SQL and SQL Server 2000 c...

Find earliest and latest dates of specified records from a table using SQL

Hi I have a table (in MS SQL 2005) with a selection of dates. I want to be able to apply a WHERE statement to return a group of them and then return which date is the earliest from one column and which one is the latest from another column. Here is an example table: ID StartDate EndDate Person 1 01/03/2010 03/03/2010 Paul 2 12/05...