Skip to content
Advertisement

Tag: tsql

How to use scalar variable in XML Path query SQL?

I want to pass table name into into a scalar variable @Table_Name as a string. But I am getting error as: Must declare the table variable @Table_Name. How to achieve the same? Below is my code snippet: Answer So I created a temporary table using the input provided by the user and used that temp table in the query. Following

How to group by row in diferents columns

I have this table in SQL, I need to group it by the report name and I need to split the price_bucket column and the count_sales column in diferents rows. I think that I should use the PIVOT funtion in SQL Server and an intermediate table. How should I do it? This is what the final table should look like:

Building an Employee Date Matrix

I have a list of employees, along with list of cities they’ve worked in. I need to build a matrix (in SQL Server) of start/end dates by city to determine where they were at any given period in time. The “end date” would be exactly the date before they appeared at a new location. I’ve included an example of the

SQL: Delete XML node in an UPDATE statement

I keep getting this error: In search of a solution to this answer I came across this SO article about updating in a SELECT statement: How do I UPDATE from a SELECT in SQL Server? Example… Note: the field CustomProperties is nvarchar(max) which I convert to xml. I also tried a cursor (nasty things), but getting the same error. Is

Advertisement