sql-server-2008-r2

Percentile aggregate for SQL Server 2008 R2

不打扰是莪最后的温柔 提交于 2019-12-19 04:55:21
问题 I'm using SQL Server 2008 R2. I need to compute a percentile value per group, something like: SELECT id, PCTL(0.9, x) -- for the 90th percentile FROM my_table GROUP BY id ORDER BY id For example, given this DDL (fiddle) --- CREATE TABLE my_table (id INT, x REAL); INSERT INTO my_table VALUES (7, 0.164595), (5, 0.671311), (7, 0.0118385), (6, 0.704592), (3, 0.633521), (3, 0.337268), (0, 0.54739), (6, 0.312282), (0, 0.220618), (7, 0.214973), (6, 0.410768), (7, 0.151572), (7, 0.0639506), (5, 0

SQL Server 2008 R2 Varbinary Max Size

时光总嘲笑我的痴心妄想 提交于 2019-12-19 00:48:28
问题 What is the max size of a file that I can insert using varbinary(max) in SQL Server 2008 R2? I tried to change the max value in the column to more than 8,000 bytes but it won't let me, so I'm guessing the max is 8,000 bytes, but from this article on MSDN, it says that the max storage size is 2^31-1 bytes: varbinary [ ( n | max ) ] Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual

How to set identity column to created table in SQL server

蓝咒 提交于 2019-12-18 19:27:12
问题 I created a table in SQL Server like this: CREATE TABLE [UserName] ( [ID] [int] NOT NULL , [Name] [nvarchar] (50) NOT NULL , [Address] [nvarchar] (200) NULL CONSTRAINT [PK_UserName] PRIMARY KEY CLUSTERED ([ID] ASC) ) ON [PRIMARY] GO If I want to make ID an identity column, what do I need? Do I need to drop and create this table and set ID to [ID] [int] IDENTITY(1,1) NOT NULL . By using drop and create, all of data from UserName table are lost . Is there another way to set IDENTITY COLUMN to

Execute stored procedure with array-like string separated by comma [duplicate]

情到浓时终转凉″ 提交于 2019-12-18 18:48:29
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Help with a sql search query using a comma delimitted parameter I want to write a stored procedure that performs a select on a table and need one input variable of type varchar(max) . I'd like to send a bunch of values separated by , as the input parameter, e.g. 'Jack','Jane','Joe' and then get the rows that contain one of these names. In SQL the code would be Select * from Personnel where Name in ('Jack','Joe',

Execute stored procedure with array-like string separated by comma [duplicate]

↘锁芯ラ 提交于 2019-12-18 18:48:09
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Help with a sql search query using a comma delimitted parameter I want to write a stored procedure that performs a select on a table and need one input variable of type varchar(max) . I'd like to send a bunch of values separated by , as the input parameter, e.g. 'Jack','Jane','Joe' and then get the rows that contain one of these names. In SQL the code would be Select * from Personnel where Name in ('Jack','Joe',

What is the best way to fetch records batch-wise from SQL Server

限于喜欢 提交于 2019-12-18 16:31:40
问题 Scenario : we are fetching rows from SQL Server to C#.Net console application and doing action on the retrieved data from SQL Server through stored procedure; after the action is performed the new data is stored into the MongoDB using C#-MongoDB-Driver. Issue : There are billions of rows. My stored procedure contains query as follows: select * from table_name To work out some batch-wise logic there is no identity column nor any date columns or such. Information : As of now the application is

Construct DateTime using today's date at a specific time

爷,独闯天下 提交于 2019-12-18 13:20:13
问题 I'd like to get 4:30 PM of the current day. Hard-coding this way doesn't work: SELECT '07242012 16:30:00.000' This is proving to be more difficult than I thought it would be. How do I approach this? 回答1: SQL Server 2000 / 2005: SELECT DATEADD(MINUTE, 30, DATEADD(HOUR, 16, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP))); -- or SELECT DATEADD(MINUTE, (16*60) + 30, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP)) -- or SELECT CONVERT(DATETIME, CONVERT(CHAR(9), CURRENT_TIMESTAMP, 112) + '16:30'); SQL Server 2008+:

Construct DateTime using today's date at a specific time

余生长醉 提交于 2019-12-18 13:18:56
问题 I'd like to get 4:30 PM of the current day. Hard-coding this way doesn't work: SELECT '07242012 16:30:00.000' This is proving to be more difficult than I thought it would be. How do I approach this? 回答1: SQL Server 2000 / 2005: SELECT DATEADD(MINUTE, 30, DATEADD(HOUR, 16, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP))); -- or SELECT DATEADD(MINUTE, (16*60) + 30, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP)) -- or SELECT CONVERT(DATETIME, CONVERT(CHAR(9), CURRENT_TIMESTAMP, 112) + '16:30'); SQL Server 2008+:

How to prevent arithmetic overflow error when using SUM on INT column?

倖福魔咒の 提交于 2019-12-18 12:09:25
问题 I am using SQL Server 2008 R2 and I have an INT column where the data inserted never surpasses the max INT , but I have a query which uses the SUM function which when executed surpasses the max INT limit and throws the error mentioned in the title. I want to be able to execute this query without changing the column type from INT to BIGINT . Here is my query: SELECT UserId, SUM( PokemonExp ) AS TotalExp, MAX( PokemonLevel ) AS MaxPokeLevel FROM mytable GROUP BY UserId ORDER BY TotalExp DESC

TSQL query to find un-used stored procedures

孤街醉人 提交于 2019-12-18 11:55:22
问题 I am trying to track down all stored procedures in a database that have never been used, or that have not been used in many months. I would like to find a query to show all the stored procedures that are not in use so that those stored procedures can be analyzed to determine if they can be removed. I am familiar with sys.procedures, but don't know how to determine if a procedure is in use or not. SELECT * FROM sys.procedures; Using SQL Server 2008 R2. UPDATE UPDATE UPDATE Using the query from