sql-server-2012

use expression to dynamically decide which subreport to open

蹲街弑〆低调 提交于 2019-12-22 08:38:35
问题 I have a report that contains several pages with graphs, tables and so on. This report is used by different customers who always want small modifications to the report. At the moment if a customer wants a change on page 5 the whole report is recreated with the modifications, even though the only change is in the graph on page 5. More so, some customers don't want to see page 3, others want a custom table at page 6. My boss would like the report to be modular so he can simply switch parts on

How to unpivot columns using CROSS APPLY in SQL Server 2012

北城余情 提交于 2019-12-22 08:37:21
问题 I want to use CROSS APPLY to UNPIVOT multiple columns. The columns CGL, CPL, EO should become Coverage Type, the values for CGL, CPL, EO should go in column Premium , and values for CGLTria,CPLTria,EOTria should go in column Tria Premium declare @TestDate table ( QuoteGUID varchar(8000), CGL money, CGLTria money, CPL money, CPLTria money, EO money, EOTria money ) INSERT INTO @TestDate (QuoteGUID, CGL, CGLTria, CPL, CPLTria, EO, EOTria) VALUES ('2D62B895-92B7-4A76-86AF-00138C5C8540', 2000, 160

SQL Server Reverse Running Total

倾然丶 夕夏残阳落幕 提交于 2019-12-22 08:20:39
问题 I have this table: id ID Date Cumulative 1 x Jan-10 10 3 x Feb-10 40 7 x Apr-10 60 9 x May-10 100 2 y Jan-10 20 6 y Mar-10 40 8 y Apr-10 60 10 y May-10 100 I need to Reverse the "Cumulative" in MS SQL Server Query to be as the following id ID Date Cumulative Reversed 1 x Jan-10 10 10 3 x Feb-10 40 30 7 x Apr-10 60 20 9 x May-10 100 40 2 y Jan-10 20 20 6 y Mar-10 40 20 8 y Apr-10 60 20 10 y May-10 100 40 Note: query is for SQL Server 2012 回答1: You can use lag to get the value in the previous

Fetching complex objects by raw SQL query in Entity Framework

半城伤御伤魂 提交于 2019-12-22 05:34:20
问题 I would like to fetch from database complex object using single query. Let's look at the following example: SELECT TableA.*, TableB.* FROM TableA INNER JOIN TableA.B_Id = TableB.Id and corresponding classes: public class QueryResult { public TableA A { get; set; } public TableB B { get; set; } } public class TableA { public int Id { get; set; } public string SomeContentA { get; set; } public int B_Id { get; set; } } public class TableB { public int Id { get; set; } public int SomeContentB {

DELETE WITH INTERSECT

て烟熏妆下的殇ゞ 提交于 2019-12-22 05:22:10
问题 I have two tables with the same number of columns with no primary keys (I know, this is not my fault). Now I need to delete all rows from table A that exists in table B (they are equal, each one with 30 columns). The most immediate way I thought is to do a INNER JOIN and solve my problem. But, write conditions for all columns (worrying about NULL ) is not elegant (maybe cause my tables are not elegant either). I want to use INTERSECT . I am not knowing how to do it? This is my first question:

How to solve Error 26: Error Locating Server/Instance Specified in production environment?

让人想犯罪 __ 提交于 2019-12-22 04:47:11
问题 I have a strange error in production environment BUT not in develop environment. In my develop environment, with Visual studio 2010, i can connect without problem to Sql Server 2012. When i copy my Windows Form app to others PC in the same network, i get an "Error 26:Error Locating Server/Instance Specified". The same application worked good with an old database instance with Sql Server 2008. I don't know what to check and where to start! EDIT: Another strange behavior is that it works good

SQL Server: Lead/Lag analytic function across groups (and not within groups)

会有一股神秘感。 提交于 2019-12-22 04:32:42
问题 Sorry for the long post, but I have provided copy & paste sample data and a possible solution approach below. The relevant part of the question is in the upper part of the post (above the horizontal rule). I have the following table Dt customer_id buy_time money_spent ------------------------------------------------- 2000-01-04 100 11:00:00.00 2 2000-01-05 100 16:00:00.00 1 2000-01-10 100 13:00:00.00 4 2000-01-10 100 14:00:00.00 3 2000-01-04 200 09:00:00.00 10 2000-01-06 200 10:00:00.00 11

How to format datetime in SQL SERVER

僤鯓⒐⒋嵵緔 提交于 2019-12-22 03:54:30
问题 I am trying to port MySQL function DATE_FORMAT(date,'%y-%m-%d %h:%i:%s %p') to MsSQL equivalent by using CONVERT() . How to format equivalent datetime string in SQL SERVER 2012 to give this output '2014-05-24 01:24:37 AM' ? 回答1: In SQL Server 2012 and up you can use FORMAT(): SELECT FORMAT(CURRENT_TIMESTAMP, 'yyyy-MM-dd hh:mm:ss tt') In prior versions, you might need to concatenate two or more different datetime conversions to get what you need, for example: SELECT CONVERT(CHAR(10), CURRENT

SQL Server 2014 backup to 2012

佐手、 提交于 2019-12-22 03:51:56
问题 Are there any tools to convert SQL Server 2014 database to 2012? I tried Generate Script but the generated script with data is too large and SQL Server Management Studio did not execute it, I need to have both schema and data. 回答1: To my knowledge, there are basically three two options for migrating a database to a lower version of SQL Server, without using 3rd party tools: Generate Scripts (not really suitable for large amounts of data) Custom Scripting and BCP or Import/Export Wizard SQL

Update or insert of view or function failed because it contains a derived or constant field

北城余情 提交于 2019-12-22 03:24:11
问题 I have been trying to understand what is wrong with the following view, and unfortunately I was not able to find my answer anywhere, other than using triggers, which I would like to avoid. Given the following view, when I try to insert into it I get the error above, however if I remove the inner join to the Company table everything seems to work just fine: CREATE VIEW [dbo].[vwCheckBookingToCheck] WITH SCHEMABINDING AS SELECT [checkUser].[CheckID] , [checkUser].[CheckToTypeID] , [checkUser].