Questions tagged [set-based]

48 questions
12
votes
2 answers

RBAR vs. Set based programming for SQL

Having read this link on RBAR and this, my understanding of RBAR amounts to this: Anything that have loops and cursors Anything that's not set based I know this sounds kinda wholly which is why I am asking if anyone has a more elegant explanation…
super9
  • 26,033
  • 36
  • 110
  • 168
6
votes
2 answers

Trying to avoid RBAR! How to correlate an insert on a related table as a set based operation?

Assume a schema that consists of the following tables: Baz BazID (PK, Identity) Description FooTemplate (A Baz may have zero to many FooTemplates) FooTemplateID (PK, Identity) BazID (FK) Description NextGenerationDate BarTemplate (A FooTemplate…
Nathan
  • 503
  • 3
  • 10
5
votes
1 answer

MySql: Operate on Many Rows Using Long List of Composite PKs

What's a good way to work with many rows in MySql, given that I have a long list of keys in a client application that is connecting with ODBC? Note: my experience is largely SQL Server, so I know a bit, just not MySQL specifically. The task is to…
ErikE
  • 43,574
  • 19
  • 137
  • 181
4
votes
4 answers

When are TSQL Cursors the best or only option?

I'm having this argument about using Cursors in TSQL recently... First of all, I'm not a cheerleader in the debate. But every time someone says cursor, there's always some knucklehead (or 50) who pounce with the obligatory 'cursors are evil'…
Chains
  • 11,681
  • 8
  • 40
  • 61
3
votes
1 answer

TSQL to insert a set of rows and dependent rows

I have 2 tables: Order (with a identity order id field) OrderItems (with a foreign key to order id) In a stored proc, I have a list of orders that I need to duplicate. Is there a good way to do this in a stored proc without a cursor? Edit: This…
Adam Tegen
  • 23,348
  • 32
  • 115
  • 149
3
votes
2 answers

Set-based execution; SQL and .NET

In SQL, one should always strive for set-based operations versus iteration-based (i.e. looping). In .NET, we frequently loop collections and objects. Are there any commands in .NET that allow set-based processing or is everything iteration-based?…
Brad
  • 14,569
  • 6
  • 34
  • 54
3
votes
1 answer

How do I convert this procedural SQL code for generating a menu hierarchy to a SET based approach?

I have a SQL Server 2008 R2 database table containing hierarchy information in the following format: MarketID Time menuPath SID MarketName 107397507 2012-11-18…
Dan
  • 65
  • 5
3
votes
2 answers

How to find the longest sequence of letter in a string

I want to find out the longest sequence of letter in a string e.g. in the word Honorificabcdwert , the output will be abcd. How can I do it? My idea is to get the Ascii and then count the sequence until it breaks at some point. But I was able to…
user1323981
2
votes
1 answer

MySQL: standard approach VS set-based approach for multi-row results

Following up on this question, there is problem with the standard approach or a recursive approach in the case below. For instance, I want to return the page with the same parent_id and some pages have multiple row contents, page table page_id …
laukok
  • 47,545
  • 146
  • 388
  • 689
2
votes
0 answers

Avoiding While Loop in T-SQL

I needed to develop a scheduled job to be executed daily at nights. I've completed the task but had to use a While loop. Which makes me feel "guilty". I'm in need of some advices about how to convert this operation into a set-based operation and…
OzanYukruk
  • 205
  • 4
  • 13
2
votes
2 answers

Insert data from staging table into multiple, related tables?

I'm working on an application that imports data from Access to SQL Server 2008. Currently, I'm using a stored procedure to import the data individually by record. I can't go with a bulk insert or anything like that because the data is inserted into…
John Straka
  • 1,754
  • 5
  • 27
  • 49
2
votes
3 answers

Set based query to replace loop to populate all month end dates from given date for all records

I have a table that stores patient lab test results. There can be results from multiple tests like Albumin, Potassium, Phosphorus etc. First reading for each patient from each of these categories is stored in a table called…
LCJ
  • 20,854
  • 59
  • 228
  • 387
2
votes
2 answers

SQL Server: Most efficient way to look for set based on 2 columns

Edit: I realized I asked the question wrong. What I really meant to ask was, "given a set of values for [Column B], check if there is a value in [Column A] that matches all of the set and no others." I'm not sure if what I want to do has an…
mbm29414
  • 11,300
  • 6
  • 52
  • 82
2
votes
1 answer

when will kubernetes service supoort set-based selector?

As the doc says: Newer resources, such as Job, Deployment, Replica Set, and Daemon Set, support set-based requirements as well. Why does the resource service not support set-based requirements? When will it support that? I want to create a service…
aloisio
  • 159
  • 3
  • 7
2
votes
3 answers

Number duplicate records on the MySQL table

Have a table with similar schema id control code amount 1 200 12 300 2 400 12 300 3 200 12 300 4 100 10 400 5 100 10 400 6 500 13 500 Trying to list the duplicates of records on a UI. Using following…
Pranav
  • 831
  • 8
  • 19
1
2 3 4