table with multiple IDs but seperate notes need sorting (Tried SQL code to make a union query)

I have 2 tables, both with an ID and notes, these IDs and notes need blending, I do not know where to start with this, here is an example of what I have TBL_1 ID Info 1 Comment 1 2 Comment 2 3 Comment 3 4 Comment 4 TBL_2 ID Info 2 Comment 5 4 […]

SQL Computed column

I am facing an issue: I have written a query and got the desired results but now my need arises that I have to add a column which can be calculated by query results. I want the new column to have the condition that if CAT6 is A then its good if B then BETTER […]

After Adding a Contract to a Service in Service Broker

We have a working (mostly) Service Broker setup. One problem is that we forgot to add a message type (EndTransmission) to the contract so I created a new contract and added it to the two services. CREATE CONTRACT [] ([] SENT BY ANY) ALTER SERVICE [//Locations/Here/Send/VolatileDataReceiveService] (ADD CONTRACT []) ; ALTER SERVICE [//Locations/Here/Send/VolatileDataSendService] (ADD CONTRACT […]

Creating contra values in the same column SQL

Aim to write a statement to produce a table with a numeric column that contains contra values, e.g. Ref Value a 100 b 75 c 50 c -50 b -75 a -100 I am new to SQL but aware it works row by row, so the only way I could think of doing this is […]

Manage SSDT project file properly with version control (*.sqlproj)

We have constant problem with project XML file (*.sqlproj). If the files are added/renoved/changed location then it automatically adds/removes records in some unexpected places. After that we have big troubles by merging it when somebody changes that file also. We came to conclusion that we might sort it before checkin. We would alphabetically sort it […]

Using Identity Insert on a linked server

I have created a linked server object in SQL management studio on our on premise SQL box and I can insert into it as following syntax: insert into [Azure].[budget].dbo.Bill I want to set identity insert and have tried the following: SET IDENTITY_INSERT [Azure].[budget].dbo.Bill ON insert into [Azure].[budget].dbo.Bill This is yielding the error that there are […]

SQL data processing

I have an MS SQL database where sensor data is being streamed from a low level device, into say column 1. In columns 2 and 3 I have some alarm levels. What I would like to do is for “some script” to test the data as it arrives in column 1 against the levels in […]

How to solve error ORDER BY clause is invalid in views, inline functions, derived tables, subqueries

This select statement in SQL Server returns this error: The ORDER BY clause is invalid in views, inline functions, derived tables, sub queries, and common table expressions, unless TOP or FOR XML is also specified. I need the order by and I can’t remove it SELECT * FROM ( SELECT stat_flag , stat_amount , stat_desc […]

Norwegian character sorting wrongly in sql order by

I just want to sort LastName column in Ent table. select distinct LastName from Ent order by LastName desc result set contains some Norwegian characters(Å,ø) DB and related column collation is ‘Danish_Norwegian_CI_AS’ my issue is it’s showing ‘Aabakken'(which id = 141) ‘Aaa'(which id = 142) and ‘Aa’ (which id = 143) in here.I believe those […]

Group by a list in the where clause and then show the row whether it has a value or is null

I was working on this query for awhile and I’m trying to figure out how to get this query to show all the initials in the where clause in the output table regardless as to whether that person has a p.Id or not. This is because I will be putting this information into a pre-formatted […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.