sql-server-2012

grouping and switching the columns and rows

我与影子孤独终老i 提交于 2019-12-05 03:42:33
问题 I don't know if this would officially be called a pivot, but the result that I would like is this: +------+---------+------+ | Alex | Charley | Liza | +------+---------+------+ | 213 | 345 | 1 | | 23 | 111 | 5 | | 42 | 52 | 2 | | 323 | | 5 | | 23 | | 1 | | 324 | | 5 | +------+---------+------+ my input data is in this form: +-----+---------+ | Apt | Name | +-----+---------+ | 213 | Alex | | 23 | Alex | | 42 | Alex | | 323 | Alex | | 23 | Alex | | 324 | Alex | | 345 | Charley | | 111 | Charley

More than 2 columns in a CONCAT function

时间秒杀一切 提交于 2019-12-05 03:30:15
In SQL Server 2012 I want to concat 5 columns into 1 but in the query it works but when I put in in a view it gives me an error like Msg 174, Level 15, State 1, Line 3 The CONCAT function requires 2 argument(s). What's the problem so I can fix it because concat is a good function for concatenate more than 1 column because if its null they make it empty.. CODE: SELECT 'Aan ' + A.Name AS 'Naam', { fn CONCAT('T.a.v. ', C.Salutation + ' ', C.FirstName + ' ', C.MiddleName + ' ', C.LastName) } AS 'T.a.v.', ISNULL(ISNULL(A.Address1_Line2, A.Address1_Line1), C.Address1_Line2) AS 'Adres', ISNULL(A

Azure data transfer Identity Column Seed Jumped by 10,000

时间秒杀一切 提交于 2019-12-05 02:12:56
After inserting the data via sql script that had SET IDENTITY_INSERT [dbo].[table] ON ... SET IDENTITY_INSERT [dbo].[table] OFF the identity seed has increased by 10,000 I have tried running reseed dbcc CHECKIDENT ('vendors', 'reseed', 57439) but I get the error saying the DBCC command 'CHECKIDENT' is not supported in this version of SQL Server. How to stop in the future this problem? I found this post on the web. The behavior (reseed) is by design, but has been acknowledged internally as less than optimal and a request has been made (again, internally) to change the behavior. This may or may

How to code a certain maths algorithm

谁说我不能喝 提交于 2019-12-05 02:05:23
I have been kindly given this algorithm to help me create a fixture list in SQL, but applying it as SQL code, I have no idea how to do. Is there a way somebody can guide me on how to apply it with code? Below is my tables schema and below that is the algorithm: League: [LeagueID] TINYINT IDENTITY(1,1) NOT NULL PRIMARY KEY, [LeagueName] VARCHAR(30) UNIQUE Team: [TeamID] TINYINT IDENTITY(1,1) NOT NULL PRIMARY KEY, [TeamAbbreviation] CHAR(3) UNIQUE, [TeamName] VARCHAR(50) UNIQUE, [LeagueID] TINYINT CONSTRAINT FK_Team_League FOREIGN KEY REFERENCES League(LeagueID) Fixture: [FixtureID] INT IDENTITY

SQL Server Query: Using JOIN to include NULL values

心已入冬 提交于 2019-12-05 01:59:45
I need help with the following SQL Server query where the columns a.TAProfileID and c.CountryCode have "NULL" values in the database. I want my JOIN statements to return "NULL" values where they exist. SELECT a.ReservationStayID AS 'Reservation Id', a.PMSConfirmationNumber as 'PMS No', a.CreatedOn AS 'Date Created', a.ArrivalDate AS 'Date of Arrival', a.DepartureDate AS 'Date of Departure', a.TAProfileID AS 'TA Id', a.StatusCode AS 'Status', b.PropertyCode AS 'Hotel', c.Name AS 'Travel Agency', c.CountryCode AS 'Market Code', d.CountryName AS 'Mkt' FROM ReservationStay a inner JOIN

SQL Server 2014 backup to 2012

喜你入骨 提交于 2019-12-05 01:44:11
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. 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 Server Integration Services (Transfer Database Task) First option is not suitable in your case, as noted.

How to format datetime in SQL SERVER

走远了吗. 提交于 2019-12-05 01:38:11
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' ? 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_TIMESTAMP, 23) + ' ' + RIGHT('0' + LTRIM(RIGHT(CONVERT(CHAR(20), CURRENT_TIMESTAMP, 22), 11)), 11); See the

Add datetime and time

六眼飞鱼酱① 提交于 2019-12-05 01:10:26
Server: SQL Server 2012; SP1; Developer Edition Code: declare @datetime datetime = '1900-01-01 00:00:00.000' declare @time time = '11:11:11' select @datetime + @time When I run the above code in the MASTER database, I get the error: Msg 402, Level 16, State 1, Line 3 The data types datetime and time are incompatible in the add operator. But when it's any other database, it works! Any idea why this must be happening? P.S. - In the enterprise edition, this throws an error irrespective of the database context. The above code will work with MS SqlServer 2008 but this code won't work with MS

Use SQL INSERT to Create Directories with FileTable

谁说我不能喝 提交于 2019-12-05 00:57:58
问题 Is there a way to create directories in a FileTable without using File I/O APIs? Is it just as simple as creating a SQL INSERT statement? This is my first experience with SQL Server 2012 and I'm not familiar with the limits of the FileTable from within SQL Server. 回答1: The following worked for me. Hopefully this helps out someone else. INSERT INTO FileTable0 (name,is_directory,is_archive) VALUES ('Directory', 1, 0); You should also check out Bob Beauchemin's Techdays 2012 video for more

How to fix reversed arabic characters mixed with english in SQL server

心不动则不痛 提交于 2019-12-05 00:02:53
问题 I have a sql server database has table column contains arabic and english characters in the same field just like Oracle اوراكل Seeking your help to split the arabic characters from english ones to reverse them. as the arabic characters don't have a specific positions in the field, start, end or in the middle of field. Edit The characters come from a legacy IBM mainframe application, and are stored in the wrong order, i.e. they are stored in the order they should be displayed left to right,