Case: Query below sql need 10.56 sec, and 236 rows were queried. Estimated Execution Plan: Most cost: After I try to use select into temporary table then it just need 0.03 sec Estimated Execution Plan: Then I’ve tried add below index, but it still no change. hct_mlots table create sql,total rows 88790 m…
Tag: sql-server
Move values in different columns to one row
I have the following table: With this sample data: Id is my primary key, and this should be UNIQUE in the table. This is possible for all of my rows, if I simply move all values up to one row in the above example. I only need to make this work when data looks like it is in the above
Recursive query compute parent values
I have 2 tables Persons and Sales. In Person there is relation between child and parent, I want to compute 20 percent of parent values with the following condition Persons Sales I want to get result like this I wrote this query but it does not give appropriate result Answer This should be a two steps algorith…
How do I pass a variable to a stored procedure to update a row in another database?
I need to get a value from one database for a customer and update another database with that value. The procedure below works but I need to have it go through table2 and update every customer in table1 with a matching CustomerID. I hate to use the word loop through but as I said, I am very new to this
How to create table/view with data from another SQL server?
I have a database managed by a third party vendor and have access to read-only for the tables and views. I would like to be able to create a table from this database in a remote server. Is this possible? If so, how do I do it? Thanks in advance. Hey this is what I got from SELECT @@VERSION Microsoft
Recursively Conditionally get parent Id
I have two tables: Budget Line and Expense. They are structured in such a way that an expense must have either a parent record in the budget line table, or a parent record in the expense table. I need to select all child-most expenses for each budget line. For example – BudgetLine: Id Description 1 TEST…
Trying to update column values in SQL Server based on time of insertion and getting “The column “ID” was specificed multiple times for “p””
Here is my query that’s throwing the “The column “ID” was specified multiple times for “p””: I’ve seen quite a few questions with the same error on SO but can’t seem to see what to apply in this scenario. Any help is greatly appreciated. Answer Unfortunate…
Converting image files to VARBINARY(max) in flutter
I need to store images that are captured using “image picker” in a SQL server database now, I know that the images should be stored in a “VARBINARY” datatype. I tried to convert the XFile “image” that I got from the “ImagePicker()” to VARBINARY and these are the…
SQL Getting a value from a column where another value is MIN value
I am not that experienced in SQL and I am trying to get a value from a row where another value is the min value. I tried several things and can’t find the answer on this forum. My SQL: So I have a table with all actions a driver has done during the day (Driving, resting, loading,…) and I want
Inserting multiple rows of data into a single column
Absolute SQL beginner here: I have a table ‘students’ with the columns ‘id'(primary key), ‘name’ and ‘mark’. I am now trying to add the marks for a number of students. Just using multiple UPDATE statements like seems rather dull and labor intensive. What would be the …