I am inserting parent records and child records at the same time in a stored procedure. Rather than have outside code make nested calls to create each parent and then each child of that parent (which is even slower than my current approach), I am giving the sql a comma separated list of child types that I put…
Tag: sql-server
Joining another tables results to add to a existing query
I want to add RuntimePercentage column to my existing Uptime query for a report. Below is the current queries I use now. To do this I need to join another table results to make it happen but I haven’t been able to find a solution. The where clause gives me a error because UptimeMin is only in table a. H…
How to select “Group” column name from another table in an SQL Server?
Group is column in one of the table. I am using below query. As Group is reserve keyword, getting error while executing below query: Could anyone guide? Answer Regular SQL Server way: And SQL Server does also support the ANSI SQL way (perhaps some setting needed?)
Adding Variables to SQL queries
I have the following code which returns a table from my ms sql Database How would I add the one_yrs_ago variable to the SQL query in this situation , like so : Answer Not seeing the full context but this is how I would do it in SQL Server I would say parameterize what you pass in is important as
SQL GROUP BY with LEFT JOIN MS SQL Server
I have a calendar table (c) with a set of 3 month dates: I have a Stats table (s) with views of each product on the website. I need to count the views per product per month whether there are views or not. I have followed many SO answers (SQL – Group By with Left Join) and I cannot see
Single Query To Select Based On Parameters If Or not supplied
I have used SqlDataSource and have a select query based on District & Zone as below It’s an inline query. I have tried above query but not able to figure out how to Select condition based. I want if district supplied then Select according to District, if both District & Zone supplied then Select…
Better way to handle adding new table in a query which contains union of tables which have same column names but table name and data are different
I want to rewrite the query to get the data from all the tables, currently I have 12 tables which contains exact same column names but have different table name and content. To get all the records I am currently union them like below. Here I have given example of tables how I am using them, as you can see
Delete records with duplicates and join in another table
I need to write a query (Microsoft SQL Server) to delete duplicates in the table Vehicle that have Vehicle.CarId = Car.CarId and having the same concatenation (CarId, CounterLimit, Kilometers). Table Car: Table Vehicle: Could you please help me? Answer Joining the table creating the rank based on carid,counte…
Comparing two tables without foreign key [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question There are two tables in 2 different databases one table consists of Salutations example Mr, Mi…
How to convert XML type return text into select columns
I’m trying to get the column names of a table using XML datatype and information_schema columns. When I tried to use the result in another select statement, I have the results with the repeated column name instead of the results set. I have even tried to cast it to varchar but it still failed. what have…