sql-server-2012

sql query to create columns with arithmetic expressions

百般思念 提交于 2019-12-11 07:59:44
问题 I have my sql tables and query as shown below : CREATE TABLE #ABC([Year] INT, [Month] INT, Stores INT); CREATE TABLE #DEF([Year] INT, [Month] INT, SalesStores INT); CREATE TABLE #GHI([Year] INT, [Month] INT, Products INT); INSERT #ABC VALUES (2013,1,1); INSERT #ABC VALUES (2013,1,2); INSERT #ABC VALUES (2013,2,3); INSERT #DEF VALUES (2013,1,4); INSERT #DEF VALUES (2013,1,5); INSERT #DEF VALUES (2013,2,6); INSERT #GHI VALUES (2013,1,7); INSERT #GHI VALUES (2013,1,8); INSERT #GHI VALUES (2013,2

Get N last rows from table with one stored procedure

。_饼干妹妹 提交于 2019-12-11 07:57:07
问题 I want get N last rows from table with one stored procedure. My stored procedure has some parameters like @PageNumber and @RowCount and etc. I have 2 problems : I need to count the rows and results in my user interface because I want to limit my user when he is in last page and press next page. I want my user can press last page when he is in other page. Tip: I don't want to execute my stored procedure twice to get the results and row count because it creates dynamic and need long time for

How do i set a temp variable to a value based from another table

大兔子大兔子 提交于 2019-12-11 07:53:20
问题 I am using the AdventureWorks 2012 database and I'm absolutely stumped on this one, So far I have alter proc pName ( @TranID int ) as declare @AccountID int declare @Entered datetime declare @Type char declare @Amount money declare @Service money declare @WithdrawalDecrease smallint declare @WithdrawalCount smallint set @AccountID = (select AccountID from Transactions where TransID = @TranID) set @WithdrawalCount = (select WithdrawalCount from Accounts inner join Transactions on Transactions

Newer SSRS instance with old Database Engine?

旧巷老猫 提交于 2019-12-11 07:52:05
问题 Is it possible to install a SQL Server 2012 SP1 Reporting Services instance on "server A" that points to a SQL Server 2008 R2 SP2 Database Engine instance on "server B?" I cannot seem to find any documentation that indicates interoperability between different versions of SQL Server Reporting Services and the Database Engine. 回答1: Yes, you can install just reporting services on "server A". Make sure to choose feature installation and only check "Reporting Services - Native" on the feature

Alternative for Cartesian and Cross Join

亡梦爱人 提交于 2019-12-11 07:33:59
问题 I want to output all the possible combination in two tables without using cartesian join or cross join. Is this possible? 回答1: I want to output all the possible combination in two tables without using cartesian join or cross join. Is this possible? By a strict definition level, it is not possible. Why? Because the definition of a Cartesian product is exactly what you describe (the term "Cartesian join" is not often used but is a synonym for "Cartesian product"). Hence, any method that you use

SqlServer.Dmf.dll required in Global Assembly Cache upon wpf app installation

不打扰是莪最后的温柔 提交于 2019-12-11 07:25:31
问题 I have an wpf app that creates a database to file. Just uses (LocalDB)/v11.0 in the connection string not .SQLExpress. If i go in project properties and go to publish tab and click on Application files, i tell it to Exclude SQlServer.Dmf.dll and yet when I publish it still ask for that dll. Why is this? I am not using this dll anywhere in my app nor do I think it should be required that i add it to my references. If I install Microsoft SQL Server 2012 then on the machine I'm trying to install

TSQL Query to reference previous rows

风流意气都作罢 提交于 2019-12-11 07:17:21
问题 I need help with a query. I have a query that is returning a simple set of rows. SELECT TOP 5 ReceivedYTD, InvoicedYTD, OrderedYTD, YearReported, WeekReported FROM Products WHERE ProductId = @ProductId ORDER BY YearReported DESC, WeekReported DESC The week and year reported columns are ordered by could have gaps (e.g. 1,2,4,5,6,9...) What I would like to do is also select for the change in the values from the previous record in the order sequence. So on Week 5, I could see how it changed from

difference between hex constants and decimal constants in SQL server

▼魔方 西西 提交于 2019-12-11 07:16:21
问题 As a follow up on insert control characters in nvarchar or varchar from SQL script? : What is the difference between the 0x prefixed hexadecimal constants and the decimal ones in the below SQL script? It looks like the 0x prefixed ones don't deliver integers. I'm probably in for another duh moment this evening, so please enlighten me (: select char(0x64) charx64, char(0100) char100, nchar(0x64) ncharx64, nchar(0100) nchar100, char(0x6564) charx6564, char(025956) char25956, nchar(0x6564)

T-SQL CASE Clause: Issue on specifying WHEN NULL with an Outer JOIN

断了今生、忘了曾经 提交于 2019-12-11 07:08:50
问题 Following query correctly displays all current/prospective customers' record regardless of whether an order was placed by him/her or not. But the YesNO alias of the SELECT statement below is always returning 1 even when in some cases o.OrderID is null (i.e., when a perspective customer has not placed an order yet). Why? I think the CASE statement below is correct (as shown in this response as well). I'm using SQL Server 2012 . NOTE : Please keep in mind that although the OrderID is a PK it

SQL INSERT sp_cursor Error

ε祈祈猫儿з 提交于 2019-12-11 06:59:00
问题 I have a pair of linked SQL servers: ServerA and ServerB. I want to write a simple INSERT INTO SELECT statement which will copy a row from ServerA's database to ServerB's database. ServerB's database was copied directly from ServerA's, and so they should have the exact same basic structure (same column names, etc.) The problem is that when I try to execute the following statement: INSERT INTO [ServerB].[data_collection].[dbo].[table1] SELECT * FROM [ServerA].[data_collection].[dbo].[table1] I