sql-server-2008-r2

Editing Multiple Rows by Their Order Index

喜夏-厌秋 提交于 2019-12-12 18:42:52
问题 Q: How would I go about using / applying the row number of each row in a query to a certain column in the entire query? I've added a screenshot to try and make things more obvious: [The picture is only a simple example] I would like to be able to directly use the value of the row number in such a context. (Iterate over the values, somehow?) Thanks in advance. (Sorry if the question is a bit vague) 回答1: Try this : ;WITH TEST AS ( SELECT *, ROW_NUMBER() OVER (ORDER BY id DESC) AS RowNo FROM

Sql server table partitioning - can I distribute tables across servers?

这一生的挚爱 提交于 2019-12-12 18:36:37
问题 I have read many sites, guides, etc; also note I cannot test what I am asking as do not have two computers. Table partitioning simply means that the table is logically divided, such that a particular range is handled by a particular partition only there by reducing load and also allowing parallelism. there is a mention of partitions being on different hard disks but there is never any mention of partitions being on different computers. Is that possible? So for example, data with id<50000 will

Generate **bare** CREATE TABLE and CREATE PROC statemnts in SQL Server

拜拜、爱过 提交于 2019-12-12 18:23:04
问题 The deployment procedures in my company require that SQL scripts for creation of procedures and tables, etc. be bare. Generating create scripts in SQL Server Management Studio gives you significantly more than a bare script, which is unfortunate in this case. For example, for a test table this is what SSMS generated for me: USE [DemoDB] GO /****** Object: Table [dbo].[example] Script Date: 08/07/2012 15:46:32 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[example

Migrating from SQL Server 2008r2 to SQL Sever 2012

假如想象 提交于 2019-12-12 17:38:37
问题 RAISEERROR not supported in SQL Server 2012 RAISERROR 44444 'Field ''CostCodeId'' cannot contain a null value.' How to change the syntax to make it to support in sql server 2012. Any alternative please help. 回答1: In SQL 2012 you should use THROW. Here is link New THROW statement in SQL Server 2012 回答2: For any new development work start using THROW, and if possible start replacing RAISERROR with THROW, as it can be replaced anytime in future (but I don't think in near future). RAISERROR was

LAG/LEAD equivalent with grouping (SQL Server 2008 R2)

早过忘川 提交于 2019-12-12 17:36:22
问题 Note: I am using SQL Server 2008 R2 and built in LEAD/LAG functions are not available. I need to update a table's column to contain the 'previous' and 'next' values for ProductID - the table needs to store PrevProductID (LAG), ProductID and NextProductID (LEAD). The code below does this very nicely and was adapted from Geri Reshef's answer to http://blog.sqlauthority.com/2011/11/24/sql-server-solution-to-puzzle-simulate-lead-and-lag-without-using-sql-server-2012-analytic-function/ USE

Run Stored Procedure From Access VBA

烂漫一生 提交于 2019-12-12 17:35:29
问题 I keep getting an error of Conversion failed when converting date and/or time from character string. This is my vba I am using as well as my sql server stored procedure syntax. What should I alter in order to have this run succesfully? Private Sub btnRunStoredProc_Click() Dim cmd As ADODB.Command, startdate As String, enddate As String Set cmd = New ADODB.Command startdate = "'" & Me.txtStartDate & "'" enddate = "'" & Me.txtEndDate & "'" cmd.ActiveConnection = "Provider=sqloledb;Server=Server

How to return value from stored procedure without output parameters

不羁的心 提交于 2019-12-12 17:25:21
问题 Here's psuedo-code for the stored procedure I currently use, CREATE PROC uspFoo ( @id int, @type nvarchar(255), @status bit output ) AS IF .... SET @status=1 ELSE SET @status=0 GO When executing this stored procedure, I am forced to pass an output parameter that will store its return value, DECLARE @id int, @type nvarchar(255), @status bit SET @id=.. SET @type=.. EXEC uspFoo @id, @assayType, @status output PRINT @status GO The return value, or in this case status , will either be 0 (false) or

SQL - how to refresh metadata on a User Defined Table Type

纵然是瞬间 提交于 2019-12-12 17:18:41
问题 I need to change the datatype of a User Defined Data Type (UDDT). I'm using this strategy of renaming the old UDDT and creating a new one with the orignal name. This means that any stored procedures and views will continue to work after they've been refreshed using: EXEC sys.sp_refreshsqlmodule '{objectName}' On columns I still have to call ALTER TABLE ALTER COLUMN and drop and recreate any indexes but it's relatively low-risk and scriptable. The problem I have now is with User Defined Table

how to keep sql dependency doing the its purpose

吃可爱长大的小学妹 提交于 2019-12-12 17:15:01
问题 I have a console application. I wanna keep watching the changes on a specific column in my database table. I read through internet and I have found that sql dependency is good for my purpose. I started learning about it and I did the following: create a class. In the constructor, I called the static function start and I called a function that has all the sql dependency settings. My problem When I run the application using the start click on visual studio 2013, the apps works and then stops.

Update table column values based on conditional logic

瘦欲@ 提交于 2019-12-12 16:11:22
问题 I have table like this: name | salary Tom | 10000 Mary | 20000 Jack | 30000 Lisa | 40000 Jake | 60000 I need an update query to update the salary column depending on the values it contains. Salaries need to increase by: 5000 for values between 10000 to 15000 7000 for values between 15000 to 20000 8000 for values between 20000 to 30000 10000 for values between 40000 to 60000 回答1: Try using the CASE statement within the UPDATE command UPDATE [yourtablename] SET salary = CASE WHEN salary BETWEEN