sql-server-2005

Hierarchy in SQL server 2005 with XML

半世苍凉 提交于 2019-12-20 02:26:14
问题 I wonder is there anyway to select hierarchy in SQL server 2005 and return xml format? I have a database with a lot of data (about 2000 to 3000 records), and i am now using a function in SQL server 2005 to retrieve the data in hierarchy and return an XML but it seems not perfect because it's too slow when there is a lot of data Here is my function Database ID Name Parent Order Function CREATE FUNCTION [dbo].[GetXMLTree] ( @PARENT bigint ) RETURNS XML AS BEGIN RETURN /* value */ (SELECT [ID]

Using the result of an Stored procedure in a Select statement

北慕城南 提交于 2019-12-20 02:14:04
问题 I have a stored procedure which returns a Dataset(Table) . How can I use the result of this stored procedure in a SELECT statement? I need something like this SELECT T1.* FROM Dummy T0 INNER JOIN (EXEC [dbo].[SPGetResults] '900',300,'USD') T1 ON T1.aKey=T0.aKey I'm using SQL Server 2005 回答1: Create a table-valued user-defined function instead. 回答2: I agree with Marcelo mostly, but if you are set on using a stored procedure, or your stored procedure does anything that affects data, you could

How to change programmatically non-identity column to identity one?

我们两清 提交于 2019-12-20 02:08:06
问题 I have a table with column ID that is identity one. Next I create new non-identity column new_ID and update it with values from ID column + 1. Like this: new_ID = ID + 1 Next I drop ID column and rename new_ID to name 'ID'. And how to set Identity on this new column 'ID'? I would like to do this programmatically! 回答1: As far as I know, you have to create a temporary table with the ID field created as IDENTITY, then copy all the data from the original table. Finally, you drop the original

What happens when I drop a clustered primary key in SQL 2005

微笑、不失礼 提交于 2019-12-20 00:44:10
问题 I've a PK constraint - a clustered index on two columns - which I am in the process of dropping. The command is still running after an hour. I would have thought that as I am just removing a constraint the operation would be nearly instantaneous. Can someone explain to me what is actually happening under the hood when I drop the PK? 回答1: Clustered index is not "just a constraint", it's a storage method. When you drop it, your data are being reordered from clustered storage to heap storage

String.Join in SQL

故事扮演 提交于 2019-12-19 19:58:13
问题 i want to select from a Table called RMA (simplified): idRMA| RMA_Number ----------------------- 1 RMA0006701 2 RMA0006730 3 RMA0006736 4 RMA0006739 5 RMA0006742 There is a junction table between RMA and tdefSymptomCode called trelRMA_SymptomCode : fiSymptomCode| fiRMA ----------------------- 1 1 1 2 2 2 5 3 7 3 8 3 2 5 3 5 4 5 5 5 for the sake of completeness, this is tdefSymptomCode : idSymptomCode SymptomCodeNumber SymptomCodeName 1 0000 Audio problem 2 0100 SIM problem 3 0200 Appearance

udf vs direct sql performance

拈花ヽ惹草 提交于 2019-12-19 19:49:35
问题 Using MSSQL 2005 I was playing around today with a Scalar UDF in a where statement to see some of the costs associated with making the call and io differences etc. I'm starting with 2 basic tables. Customer which has 1 million rows. and Purchases which has 100,000. Both have an auto identity column as Primary key. No other indexes defined. DBCC FREEPROCCACHE DBCC DROPCLEANBUFFERS SET STATISTICS IO ON SELECT * FROM Customer C INNER JOIN Purchases P on C.[IDENTITY] = P.CustomerID WHERE P.Amount

C#, sp_executesql and Incorrect Syntax

血红的双手。 提交于 2019-12-19 19:45:02
问题 I'm calling the code below. On the line (IDataReader dr = cmd.ExecuteReader()) sql barfs with an Incorrect syntax near 'CompanyUpdate'. using (SqlCommand cmd = new SqlCommand("CompanyUpdate")) { cmd.Parameters.Add("@CompanyID",SqlDbType.Int); cmd.Parameters.Add("@Description",SqlDbType.VarChar,50); cmd.Parameters["@CompanyID"].Value = companyid; cmd.Parameters["@Description"].Value = description; SqlConnection cn = new SqlConnection("Data Source=[datasource];Initial Catalog=dotNext;User ID=

Using Environment variables in T-SQL

試著忘記壹切 提交于 2019-12-19 19:42:30
问题 How can I read the value of a system environment variable in a T-SQL script? This is to run on SQL Server 2005. 回答1: This should give you a list (provided you allow people to execute xp_cmdshell) exec master..xp_cmdshell 'set' Note: xp_cmdshell is a security hazard ... You could also do this with a managed stored proc an extended stored proc or via a com component. 回答2: To "read the value of a system environment variable in a T-SQL script" you can set SQL Management Studio to use "sqlcmd Mode

How can I use sp_send_dbmail to send multiple queries?

若如初见. 提交于 2019-12-19 19:40:23
问题 I'm trying to send an email using sp_send_dbmail . I need it to send one query as an attachment and another as part of the body of the email. The problem is that sp_send_dbmail only has one @query parameter, and I can't see any way to add another one. Is there any way to either a) add a second query (with all of the parameters attached to it) or b) execute the query into a variable and then add that to the body of my email? I'm using sql-server 2005. TIA! 回答1: Use the @query parameter of the

How can I use sp_send_dbmail to send multiple queries?

旧城冷巷雨未停 提交于 2019-12-19 19:39:13
问题 I'm trying to send an email using sp_send_dbmail . I need it to send one query as an attachment and another as part of the body of the email. The problem is that sp_send_dbmail only has one @query parameter, and I can't see any way to add another one. Is there any way to either a) add a second query (with all of the parameters attached to it) or b) execute the query into a variable and then add that to the body of my email? I'm using sql-server 2005. TIA! 回答1: Use the @query parameter of the