sql-server-2012

Order by year, month along with cumulative sum

主宰稳场 提交于 2019-12-24 17:21:16
问题 My table "DATA123" is as follows NoticeDate------Amount 2016-02-14------60000 2015-11-06------10000 2015-12-02------10000 2016-01-13------50000 2016-01-24------10000 2015-12-29------30000 2016-01-12------20000 2015-11-18------50000 I want the output to be as Year----month----Amount----Cumulative 2015----NOV------60000------60000 2015----DEC------40000------100000 2016----JAN------80000------180000 2016----FEB------60000------240000 In short i want orderly monthly report sql query (not

Re: Computed column by subtracting two other columns in SQL Server

别来无恙 提交于 2019-12-24 16:37:24
问题 I have the following columns in my table name Trip; trip_no (PK, int, not null), ID_company (FK, int not null), plane (char(25), not null), town_from (char(25) not null), town_to (char(25) not null), time_out (datetime, not null), time_in (datetime, not null), time_out_only (time(0), null), time_in_only (time(0) null), time_in_flight (time(0) null); For the last three columns My first row would look like this; time_out_only time_in_only time_in_flight 14:30:00 17:50:00 null I want the time in

GUID Performance [closed]

℡╲_俬逩灬. 提交于 2019-12-24 16:34:14
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . We are developing a very large OLTP Database (SQL server 2012) and considering the use of GUID as primary key (I'm keeping in mind not

Can't attach the sample database in SQL Server 2012 [closed]

北城余情 提交于 2019-12-24 15:33:35
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I have downloaded the sample database for SQL Server 2012 Express but I am having the following error message whenever I try to attach

Extracting nvarchar value from XML in T-SQL: only one character returned

天涯浪子 提交于 2019-12-24 15:15:42
问题 In my T-SQL procedure I'm trying to extract a string value from the XML node using the .value() method, like this: declare @criteria xml; set @criteria = N'<criterion id="DocName"><value>abcd</value></criterion>'; declare @val nvarchar; set @val = @criteria.value('(criterion[@id="DocName"]/value)[1]', 'nvarchar'); select @val; I expected to get 'abcd' as a result, but I surprisingly got just 'a' . So, the value method returns only the 1st character of the string. Can anybody tell me, what am

Count number of user in a certain age's range base on date of birth

依然范特西╮ 提交于 2019-12-24 14:50:55
问题 I have table user that has user_id , user_name and user_dob . I want to count how many users that are under 18 year old, 18-50 and over 50. The Age calculation method need to be improved to calculate exact age but for now I am more interested in finding the method to count So I tried: SELECT COUNT ([user_id]) from [user] where (DATEDIFF(yy,[user_dob], GETDATE()) < 18) UNION ALL SELECT COUNT ([user_id]) from [user] where (DATEDIFF(yy,[user_dob], GETDATE()) >= 18 AND DATEDIFF(yy,[user_dob],

ssis send mail task: Error: An error occurred with the following error message: “The operation has timed out.”

落花浮王杯 提交于 2019-12-24 14:27:18
问题 SSIS package in question runs a series of stored procedures and fills 13 different excel files with results and sends those excel files to 13 different users in attachments. Package run stops with the message in the title of this question, sometime right in the middle of sending or for example today, on the 4th user. The files get created because I can see them in their directories so only the send mail task is failing. When I go back to visual studio and execute each send task manually, send

Pending execution

吃可爱长大的小学妹 提交于 2019-12-24 13:50:13
问题 From this morning, one of our main SSIS jobs started to always return fail when executed. When we check in the log, it seems that all execution of the job stacked with the status "Pending execution." We are using this SQL Server version: Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) Dec 28 2012 20:23:12 Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor) We have tried several things and are now out of ideas. We've read the connect: http:/

Dynamic Unpivot and split Columns SQL Server 2012

馋奶兔 提交于 2019-12-24 12:41:07
问题 I have a table as MarketOutput that has 20 Columns [Region] [LOB] [GWP 2013] [GWP 2014] [LR 2013] [LR 2014] ------------------------------------------------------------- North Workers 38902.50 37,972,404 89 82 I would like to dynamically change column to rows. Region and LOB are fixed columns, [GWP 2013], [GWP 2014], [LR 2013], [LR 2014] are dynamic columns. For next year they will be [GWP 2015] , [LR 2015] I want to unpivot the column and split the [GWP 2014] as two column [GWP], [2014]. The

Messed up SQL data - Select within update statement

橙三吉。 提交于 2019-12-24 12:41:00
问题 I accidentally ran a query twice and all the points in my database have messed up (3000 records). Top 4 for each result has fixed results but points between last and 5th are calculated (Last is 100pts). Click here for more info I essentially need this statement converting to SQL: Points = 100 + ((100 / (NumberOfResults - 4)) * (NumberOfResults - PositionOfResult)) How can I get a select statement to refer to the Select and the Update table separately. This doesn't work: UPDATE Results R1 SET