sql-server-2008-r2

Arithmetic operators against dynamic column in SQL Server 2008

强颜欢笑 提交于 2019-12-11 00:49:18
问题 I have query to create table and result below: -- tblPart PartCode[NVARCHAR(50)],UnitPrice[Decimal(18,2)] SELECT * INTO #tblPart FROM( SELECT 'A' PartCode, '10' UnitPrice UNION All SELECT 'B','11' UNION All SELECT 'C','38' UNION All SELECT 'D','20' UNION All SELECT 'E','12')part; -- tblPartCondition ConditionCode[NVARCHAR(50)],PercentagePrice[Decimal(18,2)] SELECT * INTO #tblPriceCondition FROM( SELECT 'Weekly' ConditionCode, '3' PercentagePrice UNION All SELECT 'Urgent','-5' UNION All SELECT

add column value to an xml field as an attribute

随声附和 提交于 2019-12-11 00:43:22
问题 I would like to add an attribute value to an xml field in a query. my example is below declare @table table (bookid int,xmlCol xml) insert into @table select 1, '<book title="you are not alone" author="Esther"> <EDITIONS> <edition year="2012"/> <edition year="2013"/> </EDITIONS> </book>' declare @table1 table(bookid int,quantity int) insert into @table1 select 1,3 select ??? from @table t inner join @table1 t1 on t.bookid = t1.bookid I want my final result to look like this <book title="you

How can I disable update table for all user

爷,独闯天下 提交于 2019-12-11 00:34:16
问题 I use SQL Server 2008 R2 and have a table that I want no one to update, in other words I want to disable updates on this table. For this purpose I know two methods, first is to use instead of update trigger to prevent update and second is to use permissions. I want to figure out best practices for this purpose. EDIT 1: I want to deny update for all user. 回答1: IMHO, using permissions to disable updates to a table is probably the best way to go. EDIT: Check Giving and removing permissions in

Do I need a recursive CTE to update a table that relies on itself?

∥☆過路亽.° 提交于 2019-12-11 00:29:03
问题 I need to apologize for the title. I put a lot of thought into it but didn't get too far. I have a table that looks like this: +--------------------------------------+--------------------------------------+--------------------------------------+--------------------------------------+--------+ | accountid | pricexxxxxid | accountid | pricelevelid | counts | +--------------------------------------+--------------------------------------+--------------------------------------+--------------------

how to enter ip in query linked server

冷暖自知 提交于 2019-12-11 00:13:37
问题 i have follwing query how to enter server IP in my query, please help me, DECLARE @ScopeIdentity int; EXEC 175.120.124.162.Taxi.sp_executesql N'INSERT INTO [175.110.104.162].Taxi.dbo.booking (FromLocTypeId,ToLocTypeId,FromLocId,ToLocId,VehicleTypeId,DriverId,ReturnDriverId,CustomerId,CustomerName,CustomerEmail,CustomerPhoneNo,CustomerMobileNo,JourneyTypeId,BookingNo,BookingDate,NoofPassengers,NoofLuggages,NoofHandLuggages,PickupDateTime,ReturnPickupDateTime,IsCompanyWise,CompanyId,FareRate

Efficient pagination in SQL Server 2008 R2

僤鯓⒐⒋嵵緔 提交于 2019-12-10 23:46:03
问题 I want to write a stored procedure that does the following: * Returns the number of records matching a query (to determine the number of pages to show the user) * Returns another recordset with a certain subset of records from a query for the current page. From another question I found on StackOverflow (sorry, I lost the link), I found that we do pagination like this: SELECT u.* FROM ( SELECT t.*, ROW_NUMBER() OVER (ORDER BY t.id) as rownum FROM ( [obscenely long select query] ) as t ) AS u

Transforming shape of a SQL Table using Pivot

拟墨画扇 提交于 2019-12-10 23:27:19
问题 I have some data stored in a table in the following format BatchID EntityChanged ChangeValue EERS ABC DEF EERS ABCD XYZ EERS Something SomeValue New Batch SomethingMore GHI The list of values that can appear in the "EntityChanged" columns is finite, known beforehand and has no spaces etc in it. For the sake of argument let us say that this list is - ABC, ABCD, Something, SomethingMore Then for the above dataset I would like an output of BatchID ABC ABCD Something SomethingMore EERS DEF XYZ

Using LIKE and IN and a Subquery in a single SQL Statement

我与影子孤独终老i 提交于 2019-12-10 21:21:52
问题 I am writing a query in which I am trying to search a subquery/CTE for a wildcard substring, and nesting this logic in my CASE statement. For example: SELECT CASE WHEN '%' + text + '%' IN (SELECT Column1 FROM Table) THEN 'I am in Column1' ELSE text END FROM Table Unfortunately, it looks like there is no possibly way to do this. Since I would need to use the LIKE operator and there is no way to use both LIKE and IN. I would have to write each LIKE statement separately, and that would be for

N prefix and parameter

删除回忆录丶 提交于 2019-12-10 20:47:51
问题 I have some stored procedure CREATE PROC MyProc ( @FullName NVARCHAR(200) = NULL ) AS --............. When I call this proc as exec MyProc 'Some english text' it works good. But if call it as exec MyProc 'Русский текст' that is using Russian alphabet, it doesn't work properly. And the call exec MyProc N'Русский текст' works good again. I have a client application and... I need to add N prefix to parameters? If yes, how do I do it? 回答1: The N would only be needed (manually) if you are

ASP.NET stored proc call bringing back no rows, but does in Management Studio!

家住魔仙堡 提交于 2019-12-10 20:44:02
问题 I have an unbelievably strange problem which I have been trying to fix for almost a day, and I'm now against a brick wall and need help! I have created a .NET 4 C# website on my Windows 7 PC, with a newly installed SqlServer 2008 Express R2 , and all works fine. I have uploaded the database and website. The website is now on a Windows Web Server 2008 R2 (with service pack 1) The Database is on a different server running Windows Server 2008 R2 Standard with SQL Server 2008 R2. The rest of the