T-SQL – Insert Data into Parent and Child Tables

Here is my solution (based on the same answer I’ve linked to in the comments): First, you must add another column to your UDT, to hold a temporary ID for the employee: CREATE TYPE dbo.tEmployeeData AS TABLE ( FirstName NVARCHAR(50), LastName NVARCHAR(50), DepartmentType NVARCHAR(10), DepartmentBuilding NVARCHAR(50), DepartmentEmployeeLevel NVARCHAR(10), DepartmentTypeAMetadata NVARCHAR(100), DepartmentTypeBMetadata NVARCHAR(100), EmployeeId int ) … Read more

nvarchar concatenation / index / nvarchar(max) inexplicable behavior

TLDR; This is not a documented/supported approach for concatenating strings across rows. It sometimes works but also sometimes fails as it depends what execution plan you get. Instead use one of the following guaranteed approaches SQL Server 2017+ SELECT @a = STRING_AGG([msg], ”) WITHIN GROUP (ORDER BY [priority] ASC) FROM bla where autofix = 0 … Read more

Enable remote connections for SQL Server Express 2012

Well, glad I asked. The solution I finally discovered was here: How do I configure SQL Server Express to allow remote tcp/ip connections on port 1433? Run SQL Server Configuration Manager. Go to SQL Server Network Configuration > Protocols for SQLEXPRESS. Make sure TCP/IP is enabled. So far, so good, and entirely expected. But then: … Read more