sql-server-2005

how to get top n rows from a table where value of n is passed at run-time?

痞子三分冷 提交于 2020-01-13 11:07:41
问题 How to get top n rows from a table where value of n is passed at run-time? 回答1: In SQL Server 2005 and beyond you can actually parameterise the top command. The code below is from MSDN USE AdventureWorks; GO DECLARE @p AS int; SELECT @p=10 SELECT TOP(@p)* FROM HumanResources.Employee; GO In earlier versions of SQL Server you will need to either use rowcount or dynamic sql. 回答2: You can use set rowcount. To get the first 100, for example: declare @myrowcount = 100 set rowcount @myrowcount

SQL dividing 2 values from 2 queries

谁都会走 提交于 2020-01-13 11:05:24
问题 I have 2 queries that are as follows: SELECT COUNT(cvu.[ID]), 'Exp' AS [Exp] FROM [dbo].[tblClientVehicleUnit] cvu WHERE ExpirationDate < GetDate() AND cvu.Id = '4C1' And the second one: SELECT COUNT(cvu.[ID]), 'NonExp' AS [Exp] FROM [dbo].[tblClientVehicleUnit] cvu WHERE ExpirationDate > GetDate() AND cvu.Id = '4C1' How would I divide the counts between these two? It will always only return 2 values and one will be called Exp and one will be called NonExp. Thanks 回答1: Basically treat those

Serializing a System.Array to a XML String

自古美人都是妖i 提交于 2020-01-13 10:22:37
问题 I need to pass an array of strings to SQL Server 2005, and so I wrote a stored procedure which accpets a XML parameter and deals with it properly. My question is if there is any easy way to serialize a string[] to a XML string (not a file in the disk) directly in C# without having to code my own method using XDocument, XAttribute and the like. Example : I want to be able to transform something like new string[] { "a", "b", "c" } into something like <StringList><String>a</String><String>b<

Serializing a System.Array to a XML String

廉价感情. 提交于 2020-01-13 10:21:15
问题 I need to pass an array of strings to SQL Server 2005, and so I wrote a stored procedure which accpets a XML parameter and deals with it properly. My question is if there is any easy way to serialize a string[] to a XML string (not a file in the disk) directly in C# without having to code my own method using XDocument, XAttribute and the like. Example : I want to be able to transform something like new string[] { "a", "b", "c" } into something like <StringList><String>a</String><String>b<

How to define ENUM in SQL Server 2005? [duplicate]

可紊 提交于 2020-01-13 10:11:54
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Does SQL Server 2005 have an equivalent to MySql’s ENUM data type? Is there any way to define ENUM in SQL Server 2005? I have fixed values which I need to use in procedures and functions. 回答1: Use one or more scalar UDFs? One per constant: dbo.CONST_Bicycle returns 1 dbo.CONST_Car returns 2 One per enum: dbo.CONST_Types('Bicycle') returns 1 dbo.CONST_Types('Car') returns 2 Or use a table with ID, Name per enum

What is the comparative speed of temporary tables to physical tables in SQL?

杀马特。学长 韩版系。学妹 提交于 2020-01-12 23:46:56
问题 I have a script that needs to extract data temporarily to do extra operations on it, but then doesn't need to store it any further after the script has run. I currently have the data in question in a series of temporary local tables (CREATE TABLE #table), which are then dropped as their use is completed. I was considering switching to physical tables, treated in the same way (CREATE TABLE table), if there would be an improvement in the speed of the script for it (or other advantages, maybe?).

What is the comparative speed of temporary tables to physical tables in SQL?

為{幸葍}努か 提交于 2020-01-12 23:45:47
问题 I have a script that needs to extract data temporarily to do extra operations on it, but then doesn't need to store it any further after the script has run. I currently have the data in question in a series of temporary local tables (CREATE TABLE #table), which are then dropped as their use is completed. I was considering switching to physical tables, treated in the same way (CREATE TABLE table), if there would be an improvement in the speed of the script for it (or other advantages, maybe?).

Display DataType and Size of Column from SQL Server Query Results at Runtime

百般思念 提交于 2020-01-12 15:37:25
问题 Is there a way to run a query and then have SQL Server management studio or sqlcmd or something simply display the datatype and size of each column as it was received. Seems like this information must be present for the transmission of the data to occur between the server and the client. It would be very helpful to me if it could be displayed. A little background: The reason I ask is because I must interface with countless legacy stored procedures with anywhere from 50 to 5000+ lines of code

Display DataType and Size of Column from SQL Server Query Results at Runtime

有些话、适合烂在心里 提交于 2020-01-12 15:37:12
问题 Is there a way to run a query and then have SQL Server management studio or sqlcmd or something simply display the datatype and size of each column as it was received. Seems like this information must be present for the transmission of the data to occur between the server and the client. It would be very helpful to me if it could be displayed. A little background: The reason I ask is because I must interface with countless legacy stored procedures with anywhere from 50 to 5000+ lines of code

in sql server how to get a column values with `<br>` separate

放肆的年华 提交于 2020-01-12 10:13:34
问题 In sql server how can I get a column's values with <br> separating them? Here I am getting with comma separated, but how can I get <br/> in html in sql server? SELECT STUFF( ( SELECT ',' + cast(Citation_Id as nvarchar(500)) FROM tollplus.violated_trips FOR XML PATH('') ), 1, 1, '' ) As CitationId 回答1: try this: SELECT STUFF( (SELECT '<br/>' + cast(Citation_Id as nvarchar(500)) FROM tollplus.violated_trips FOR XML PATH(''), TYPE ).value('.','varchar(max)') ,1,5, '' ) AS Citation_Id 回答2: To