I have a simple problem. I have tables A and B, both contain 3 common columns (name, id, date), and besides those 3, both tables have completely different set of columns. Now, I need to relate data from Table B to table A for visualization purposes. Since I am not that good with SQL, I thought I could ask if
Tag: sql-server
How can I join result from two queries
So sorry but I am new to SQL querying and could use a little help. I will like to join results from 2 tables and I can’t seem to get it return results I need. Query 1 Query 2 I tried using union all but I get an error must have equal number of expressions in their target lists. Any
Replace function in SQL Server
I have a string of data I am trying to use the replace function to replace double commas with NULL values Solution But I keep ending up with (The ,,, needs to become ,NULL,NULL, but only becomes ,NULL,,) Here is my sample code I’m using Answer If you do the same replacement twice, any number of sequenti…
MS SQL Find a Value in entire column and return true if found
New to SQL trying to find how to do the following : I have a ProductID# ABC123 (Product) I need to check the “workflow” (Workflow) column and see if the Product ID was ever “extended” – there are various workflow steps – Need to check the entire workflow column, if a Produc…
Grant Select To Synonym For Specified Columns
I’ve been trying to restrict a user’s select access to a synonym. Consider the following below: I get an error: Msg 1020, Level 16, State 3, Line 4 Sub-entity lists (such as column or security expressions) cannot be specified for entity-level permissions. But if I change it to use dbo.Items direct…
Correspondence between two tables
I have table the table code_Commune contains gps for the city in general code_Commune: Now I need to do correspondence with the table lead to add code_commune and Nom_Commune: Table lead Is there any way to do correspondence between the two tables? Answer You can find the closest city using some sort of dista…
Selecting 7th Person (row) and get 7 as result
I want to select the 7th person (Pierre Gasly (for example)) Score list Season F1, so I can return number 7 in my C# application. SELECT CONCAT(strVoorNaam, strTussenVoegsel, ‘ ‘, strAchterNaam) AS …
How to use Lead() and Lag() to get the first non null value
I have the following query and returns this table: now, what I’m trying to do is to calculate the lead of the first non null value on the field. for example, for event_id = 138466815 the columnCount is 85. I want the “lead1” field to show 82.53, which is the next non null value below. and th…
Stored Procedure return default value?
in my database, there is a Stored Procedure with INSERT INTO statement. The problem is I want this stored procedure will return the StudentCode default value, I think it’s impossible to use the SELECT …
SQL SERVER JOIN ID rows from one SELECT query to second SELECT query
Our fleet drivers accumulate hours in each type of rig that we operate. This first query returns a list of driver IDs for a given route. Result: I need to feed these IDs into this second query, which returns the number of accumulated hours for a given Driver ID. I’m trying to achieve: EDIT: For clarific…