Skip to content

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…

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…

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 …