sql-server-2005

Using case in a sql select statement

守給你的承諾、 提交于 2019-12-24 10:35:43
问题 Consider a table with a column amount, Amount -1235.235 1356.45 -133.25 4565.50 5023 -8791.25 I want to my result pane to be like this, Debit Credit 0 -1235.235 1356.45 0 0 -133.25 Here is my stored procedure, USE [HotelBI_CustomDB] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[SP_GetJVReport]( @p_FromDate datetime, @p_ToDate datetime ) AS BEGIN select jv.AccountNo,jv.AccountNoTitle,(select JV_GroupsHead.GroupTitle from JV_GroupsHead where JV_GroupsHead.Id=jv

Why cannot create global temporary table or truncate it when call a stored procedure from C# code?

放肆的年华 提交于 2019-12-24 10:23:55
问题 I spent whole days and hours to investigate why cannot create temporary table when I call a stored procedure from C# code. Let's assume a piece of C# code: public void GetDataByFilter(string item, string filter ...) { ... // provide stored procedure in new SqlCommand object sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add("@val1", aValue1); sqlCommand.Parameters.Add("@val2", aValue2); ... while(sqlDataReader.Read()) { /* process info here */ } } and my stored

SQL Server 2005 trigger - how to safely determine if fired by UPDATE or DELETE?

半腔热情 提交于 2019-12-24 10:23:13
问题 I have the following code in a SQL Server 2005 trigger: CREATE TRIGGER [myTrigger] ON [myTable] FOR UPDATE,DELETE AS BEGIN DECLARE @OperationType VARCHAR(6) IF EXISTS(SELECT 1 FROM INSERTED) BEGIN SET @OperationType='Update' END ELSE BEGIN SET @OperationType='Delete' END My question: is there a situation in which @OperationType is not populated correctly? E.G.: the data in the table is changed by a bunch of UPDATE/DELETE statements, but the trigger is not fired once by every one of them? Do

sql xml order processor

流过昼夜 提交于 2019-12-24 10:12:42
问题 I was wondering if anyone could point me to a tutorial or give me suggestions on processing an XML "Request For Quote" document. Using SQL Server 2005. For example: <MyQuote> <Header> <Customer>XYZ</Customer> <Material>Wood&</Material> <Header> <LineItems> <Line> <Quantity>32</Quantity> <Model>Chair 350</Model> <Color>Red</Color> </Line> . </LineItems> </MyQuote> Just getting my feet wet with XQuery. I need to shred this doc into individual Line Items, identify each one with a number,

multiple transactions within a certain time period, limited by date range

Deadly 提交于 2019-12-24 10:00:12
问题 I have a database of transactions, people, transaction dates, items, etc. Each time a person buys an item, the transaction is stored in the table like so: personNumber, TransactionNumber, TransactionDate, ItemNumber What I want to do is to find people (personNumber) who, from January 1st 2012(transactionDate) until March 1st 2012 have purchased the same ItemNumber multiple times within 14 days (configurable) or less. I then need to list all those transactions on a report. Sample data:

SQL Server 2005 cached an execution plan that could never work

为君一笑 提交于 2019-12-24 09:58:38
问题 We have a view that is used to lookup a record in a table by clustered index. The view also has a couple of subqueries in the select statement that lookup data in two large tables, also by clustered index. To hugely simplify it would be something like this: SELECT a, (SELECT b FROM tableB where tableB.a=tableA.a) as b (SELECT c FROM tableC where tableC.a=tableA.a) as c FROM tableA Most lookups to [tableB] correctly use a non-clustered index on [tableB] and work very efficiently. However, very

Concatenate '$' with numeric value

▼魔方 西西 提交于 2019-12-24 09:52:57
问题 The SelectCommand for my GridView is as follows: SELECT pubName AS Publication, COUNT(*) AS Total, SUM(CAST (price as INT)) AS Price FROM [SecureOrders] WHERE DateTime >= DATEADD(day, -1, GETDATE()) GROUP BY pubName Where I'm doing the SUM AS Price bit, I want to add a dollar sign ($) to the start, so my data displays as $109, instead of just 109. I tried just doing '$' + SUM, but of course that didn't work. Is there a way around this? 回答1: Like in many languages, the plus sign is an

trigger and transactions on temporary tables

蹲街弑〆低调 提交于 2019-12-24 09:13:58
问题 can we create trigger and transactions on temporary tables? when user will insert data then , if it is committed then the trigger would be fired , and that data would go from the temporary table into the actual tables. and when the SQL service would stop, or the server would be shutdown, then the temporary tables would be deleted automatically. or shall i use an another actual table , in which first the data would be inserted and then if it is committed then the trigger would be fired and the

Using SQL Server as resource locking mechanism

本秂侑毒 提交于 2019-12-24 08:59:15
问题 Given a table of logical resource identifiers (one per row), what is the best way for an arbitrary number of database clients to perform the following operations: Claim access to a specific resource, if it is not already claimed SELECT the next available resource and claim it (similar to above) Release a previously-claimed resource (The table would have a "claimant" column, which would be NULL in unclaimed rows.) I'm stuck on the atomicity of these operations: would I need a whole-table lock

SSRS 2005 find name of column with max value

て烟熏妆下的殇ゞ 提交于 2019-12-24 08:58:10
问题 The column on the far right is what I'm trying to add to my report. Is this possible to do without modifying the query to use something like Unpivot? Step X Step W Step A Step B Step Y Last Step --------------------------------------------------------------------- 1/21/2013 1/24/2013 1/3/2013 1/5/2013 1/7/2013 Step W This is a step in the right direction, but it appears to only work in SSRS 2008: http://www.bigator.com/2012/04/26/spothighlight-minimum-and-maximum-values-in-each-row-in-matrix