Skip to content

Tag: sql-server

How to minimize my big query for showing counts using SQL

I am taking counts from CTE but common is Status(working,pening) and Divisions but my query is becoming big because left join is same but just status and division are different. I have wrote 10 left join count but by passing status and divisions. Below is my whole sql query Is there anything which we can mini…

SQL get row count from every table tenantwise

I am working on a multitenant application. Most of the tables contain a column tenant_id. I want the number of rows in all tables for a particular tenant_id. Example, Tables:- Sample result to get number of rows in every table having tenantid = 64 TableName Count Employee 2 Student 3 Teacher 1 How do I loop t…

Pass Parameters in Pivot SQL

I had this query below and got an error with parameter @emp_group during execution. Need your suggestion on how to pass the parameter. The query will run when removing the parameter but need to filter the records. thanks in advance. Answer You can can do the same thing with @emp_group like you did with @cols.…