sql-server-2008-r2

What is the equivalent of Oracle's LAST_DAY() function in SQL Server 2008?

天大地大妈咪最大 提交于 2019-12-14 03:52:07
问题 I have used the LAST_DAY() function in Oracle like this: Last_Day( to_date( '$pay_first_day' , 'YYYY-mm-dd') ) What do i have to do in SQL server 2008 R2 database to achieve the same result? 回答1: Try this one - DECLARE @Date DATETIME SELECT @Date = GETDATE() SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, @Date) + 1, 0) - 1 回答2: -- Wrapping the answer in a function for seamless transition. CREATE FUNCTION [dbo].[LAST_DAY] ( @inDate DATETIME ) RETURNS DATETIME AS BEGIN RETURN DATEADD(MONTH, DATEDIFF

How to iterate through an SQL table which “parent” and child" rows are in same table

守給你的承諾、 提交于 2019-12-14 03:47:39
问题 In a table there are the columns ID, Title and ParentID. ParentID is used for the ID of the entry in the same table which is considered its parent - thus any entry in which ParentID is NULL is one which is itself a parent. I need a query which will iterate through each parent and list any child below it (ideally with a hyphen or something to denote its subordination) does anyone know how this can be done or how to point me in the right direction? (I've looked into T-SQL and read many similar

How to avoid hardcoding an Id in a Sql Update Trigger

寵の児 提交于 2019-12-14 03:26:23
问题 I have an Update Trigger that logs table changes to a log table. In the log table, there is a column which stores the type of change made, ie, an Insert or an Update. I then have a LogType table with three rows, one row for 'Update' and one for 'Insert' and one for 'Deleted' with Id's of 1, 2, 3. In the update trigger, and hardcode the value of 2 when I insert into the log table. But this seems to the coder in me a poor practice. The only alternate I can think of to this is having a "Key"

Create new columns in a declared query variable in SQL Server

会有一股神秘感。 提交于 2019-12-14 02:25:04
问题 I've created a stored procedure in SQL Server 2008 R2. It executes a pivot table. So, what I need for the next steps are 3 new columns, which would be create in this declared query variable. In these 3 columns I have to perform a calculation. At first, my stored procedures code: UPDATE Stored Procedure: BEGIN SET NOCOUNT ON; DECLARE @colNo nvarchar(max) DECLARE @colSum nvarchar(max) DECLARE @query nvarchar(max) SET NOCOUNT ON; WITH vals AS ( SELECT DISTINCT ds.No FROM QRTestView ds ) SELECT

SQL Server : Consecutive Rows Issue

*爱你&永不变心* 提交于 2019-12-14 00:56:41
问题 I'm having difficulty with a consecutive rows query, and need some assistance. I have a table that is part of a telephony switch. It tracks every employee who logs into a phone (and the phones extension). I have another table that tells me where that phone is (across multiple sites). The logic we're going for is if someone logs into a particular phone/site for 2 consecutive days, we'll trigger an event to update their employee record to make this site their primary location. The issue I'm

extend current query, calculated columns

元气小坏坏 提交于 2019-12-13 23:55:31
问题 My table looks for example like this: Name date result A 2012-01-01 1 A 2012-02-01 2 B 2013-01-01 1 ... For a full example: http://sqlfiddle.com/#!3/0226b/1 At the moment I have a working query that counts the rows by person and year: http://sqlfiddle.com/#!3/0226b/3 This is perfect, but what I want is some extra information for 2014. i need to count how many rows I have for every result. something like this: NAME 1 2 3 2014 2013 2012 TOTAL Person B 4 0 2 6 2 2 10 Person A 2 1 1 4 3 4 11

Conflict between sql server 2008 r2 and 2012

让人想犯罪 __ 提交于 2019-12-13 21:11:27
问题 I have both SQL Server 2008 r2 and SQL Server 2012 installed, but when I open SQL Server 2008 r2 management studio and enter by (localhost), it's version seems to be 11.0.2218 which is for sql server 2012 management studio, so I can't access or create older tables. Is there any way to change SQL Server management studio? 回答1: Open your SQL Server Configuration Manager, Under SQL Server Network Configuration you will find Protocols for and all the instances that is installed will be there.

How to add my SQL Server 2008 R2 database to my Visual Studio 2010 Setup File?

本秂侑毒 提交于 2019-12-13 21:06:59
问题 I want install my Windows application at my client location. It is a multiuser application. 10 systems with 1 server. So I install client setup on all the 10 systems and service setup on the server system. How to secure my database in client server? I am using VS2010 and SQL Server 2008 R2. With out installing SQL Server Management Studio Express, how to install my database? And how to add my database in service setup? Can anybody show me an example for this type of application? 回答1: windows

sql server driver to work with liquibase in maven

你。 提交于 2019-12-13 20:39:06
问题 I´m having a problem getting the liquibase-maven-plugin to work with MS Sql Server. I have added the lastest sqljdbc4.jar to my local maven repo and I have generated a changeset from my existing database by running the liquibase.bat. When i try to run mvn liquibase:update I get the following exception Failed to execute goal org.liquibase:liquibase-maven-plugin:2.0.5:update (default-cli) on project parent: The driver has not been specified either as a parameter or in a properties file. This is

SQL Table highest sequence number [duplicate]

耗尽温柔 提交于 2019-12-13 19:06:15
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Selecting the Highest Seq Number by nested Joining Hello I have to write a query , I would like to take biggest sequence number for each client Id (big sequence number will be calculated based on highest bank account balance). Please consider this table has 100000records. table is like as below- Table: **ClID** **SeqNu** **Bal** 1 1 30000 1 2 26789 1 3 23456 1 4 12345 1 5 21234 2 3 12456 2 4 45632 2 1 23456 2 9