I have table with 3 columns (id, Name, Occurrence), I want to update the Occurrence column ,based on the id column, attached snap for the reference. for example if my id column has “606” value 3 times then my occurrent column should have 3 against all the “606” value. Below is the method which I tried. I tried to find
Tag: tsql
How to get 1st and 3rd Saturday and all Sunday between 2 dates using sql
Given a date range, I’d like to return all of the Saturdays and Sundays that fall within that range, with these conditions: Include Saturdays only if their ordinal position is either the 1st or 3rd Saturday within the month they fall (not within the entire range). Include all Sundays, along with the ordinal position of that Sunday within the month
How do I merge OUTER JOIN and UNION results?
I have two tables, and I want ALL the data from both. If the tables have a matching AssetID, then join them on one row. If not, then on separate rows. A full outer join sounds like the right approach but I have a problem in how to select the keys depending on which table it comes from. Goal: Produces
How to count rows by date for each of two values?
I have a large dataset in SQL Server that contains two date fields and a foreign key field (among others): I need a query that can count the number of rows for each day, but to count them for each distinct value in the type_id column. The closest I can wrap my brain around right now is returning the total
T-SQL stored procedure: update local variable inside IF/ELSE statement
I have an item table that has a foreign key constraint customer_id that references a customer table. The customer_id column is of type uniqueidentifier which needs to be generated on insert (there is no value we could use for this provided by the client). I am created a T-SQL (using SQL Server Express) stored procedure to be called from C#
query to get data between date ranges and the padded data around
suppose this is my data in a table in the database and this is my query to fetch data I would also like the query to return one date before and after this range. so like the dates padded. Now how can i do this efficiently. One way could be to get the dates in the ranges and then get
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. How
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 according to both & If nothing
How to Add missing Months and display TotalPayment = 0
How to Add missing Months and display TotalPayment as 0 I already try row_number but it seems not working Query: Results: brgy month_dt TotalPayment barangay1 January 5345.00 barangay1 February 34232.00 barangay1 March 53454.00 barangay1 April 25234.00 barangay1 May 43224.00 barangay1 June 14.00 barangay1 July 141.00 barangay1 August 4415.00 barangay1 September 5455.00 barangay1 October 1235.00 barangay1 November 53535.00 barangay1 December 1661.00
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