sql-server-2005

Optimizing SQL queries by removing Sort operator in Execution plan

纵饮孤独 提交于 2020-01-12 03:11:16
问题 I’ve just started looking into optimizing my queries through indexes because SQL data is growing large and fast. I looked at how the optimizer is processing my query through the Execution plan in SSMS and noticed that a Sort operator is being used. I’ve heard that a Sort operator indicates a bad design in the query since the sort can be made prematurely through an index. So here is an example table and data similar to what I’m doing: IF OBJECT_ID('dbo.Store') IS NOT NULL DROP TABLE dbo.[Store

Optimizing SQL queries by removing Sort operator in Execution plan

狂风中的少年 提交于 2020-01-12 03:11:09
问题 I’ve just started looking into optimizing my queries through indexes because SQL data is growing large and fast. I looked at how the optimizer is processing my query through the Execution plan in SSMS and noticed that a Sort operator is being used. I’ve heard that a Sort operator indicates a bad design in the query since the sort can be made prematurely through an index. So here is an example table and data similar to what I’m doing: IF OBJECT_ID('dbo.Store') IS NOT NULL DROP TABLE dbo.[Store

SQL server profiler not showing LINQ To Sql queries

被刻印的时光 ゝ 提交于 2020-01-12 02:50:47
问题 I am trying to view SQL generated by Linq to SQL in the SQL Server Profiler (2005). I can see the sql sent to the server from anything except for linq to sql. I'm betting that I need to change event selections for the trace, but not sure what else to select. I am currently only selecting this: SQL:StmtCompleted - TextData & SPID I don't want to use data context logging nor the SQL Debug Visualizer. I need to use the profiler. Why can I not see the LINQ to SQL queries? Thanks. EDIT I added SQL

how to generate a query in SQL SERVER 2005 which gives output like Matrix?

流过昼夜 提交于 2020-01-11 13:43:07
问题 H i have column which consists of 32 rows. like ColumnA 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 while retrieving i want (4 X 8) means 4 columns 8 Rows.The Result should be like this A B C D 1 9 17 25 2 10 18 26 3 11 19 27 4 12 20 28 5 13 21 29 6 14 22 30 7 15 23 31 8 16 24 32 Give me an Idea. 回答1: Something like this using CTE and row_number() : Fiddle demo declare @numRows int = 8 ;with cte as ( select columnA X, row_number() over (order by

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value

筅森魡賤 提交于 2020-01-11 13:41:26
问题 I have a WPF application. date is my table and its two columns are employeename ( varchar(10) ) and date ( datetime ) My code is: Sqlconncetion con = new Sqlconnection("my database connection "); SqlCommand cmd = new SqlCommand("insert into date values('"+textBox1.Text+"','"+datePicker1.Text+"')", con); con.Open(); int n = cmd.ExecuteNonQuery(); if (n > 0) { MessageBox.Show("insert"); } Actually my WPF datepicker formats inputs as "dd/mm/yyyy " and SQL Server table accept date format mm/dd

Week() function in sql script

本秂侑毒 提交于 2020-01-11 10:32:17
问题 I am using sql server 2005. I just want to know is there something we can get the week number for the particular month. Example Date = '2008-10-16' Is there something we can have SELECT WEEK(Date) . Or any better suggestion. 回答1: select (datepart(dd,'2008-10-08')-1) / 7 + 1 回答2: You can do it this way: SET @weeksinmonth=datediff(week, @date, @lastdate) + 1 That is a copy-and-paste out of one of my stored procedures. 回答3: SELECT DATEPART( week, '2008-10-16') 来源: https://stackoverflow.com

Reporting Services - Multi-value parameter query returning no results

别等时光非礼了梦想. 提交于 2020-01-11 10:24:07
问题 Using SSRS (SQL Server 2005) I've set up two reports. For ease of explanation, let's call them MAIN_REPORT and SUB_REPORT . MAIN_REPORT runs a query that returns a set of Areas, with multiple TagNames per area: AREA Tagname ---------- A1 T1 A1 T2 A2 T3 A3 T4 If you select one of the Area cells, it opens SUB_REPORT and passes a parameter to @ParentTagNames using Join(Parameters!ResultsOfSearch.Value,",") . ResultsOfSearch is equal to the Tagname column above (haven't yet figured out how to

Entity framework 4 not closing connection in sql server 2005 profiler

谁都会走 提交于 2020-01-11 09:34:09
问题 I'm using entity framework 4 for the first time in an ASP.net application. I wanted to make sure that DB connections are closed after leaving the using statement, however, in the SQL Server 2005 profiler, I cannot see the connection logout when leaving the using, only the login when entering it, For example, I started with a blank asp.net page, and in the Page_Load, I tried with this simple code (and absolutly nothing else in the page) : using (var model = new DB("name=DB")) { var livre =

How can I attach a database?

情到浓时终转凉″ 提交于 2020-01-11 09:32:12
问题 When I want to attach database, an error occurs: The database 'Almizan' cannot be opened because it is version 661. This server supports version 655 and earlier. A downgrade path is not supported. Could not open new database 'Almizan'. CREATE DATABASE is aborted. (.Net SqlClient Data Provider) Help me to attach this database. 回答1: Install SQL Server 2008 EXPRESS R2. There is a bug in the Web Platform Installer and it still thinks EXPRESS R1 is the latest version. SQL Server 2008 databases are

Strange problem with SQL Server procedure execution plan

心已入冬 提交于 2020-01-11 09:14:14
问题 I was wondering if you guys could help me get to the bottom of a weird problem I have recently had on SQL Server. I have a stored procedure (lets call SPold ) which is reasonably large with a lot of calculations (can't possibly do this in app as info for around 6000 users needs to come back in a one-er (I reduce this to 1000 based on Surname)). The stored procedure usually executes in a couple of seconds, and is called once every couple of minutes. Now this morning, the stored procedure was