I have a model Exercises and it has columns of :circuit and :order (among others). In a view, I am trying to order the Exercises first by :circuit and then by :order. When I use the following: @…
How to fill Dataset with multiple tables?
I’m trying to fill DataSet which contains 2 tables with one to many relationship. I’m using DataReader to achieve this : But I’ve got only one table filled up. How do I achieve my goal – fill both tables? I would like to use DataReader instead DataAdapter, if it possible. Answer If you…
Add WHERE clauses to SQL dynamically / programmatically
How can I add search condition to SQL Stored Procedure programmatically? In my application(C#) I’m using stored procedure (SQL Server 2008R2) ALTER PROCEDURE [dbo].[PROC001] @userID varchar(20), @…
Can I parameterize the table name in a prepared statement?
I’ve used the mysqli_stmt_bind_param function several times. However, if I separate variables that I’m trying to protect against SQL injection I run into errors. Here’s some code sample: Is it possible to somehow replace the .$new_table. concatenation with another question mark statement, ma…
PostgreSQL IF statement
How can I do such query in Postgres? IF (select count(*) from orders) > 0 THEN DELETE from orders ELSE INSERT INTO orders values (1,2,3);
How to create id with AUTO_INCREMENT on Oracle?
It appears that there is no concept of AUTO_INCREMENT in Oracle, up until and including version 11g. How can I create a column that behaves like auto increment in Oracle 11g?
How do I create a trigger to insert a value into an ID field that is Max([ID Field])+1 on insert
When I add a new record I want SQL Server to automatically add a fresh ID. There are already some records which have been migrated over (from Access) and until I finish preparing the server for other required functionality I will be manually migrating further records over (if this affects any possible answers…
SQL performance MAX()
Just got a small question. When trying to get a single max-Value of a table. Which one is better? or I’m using Microsoft SQL Server 2012 Answer There will be no difference as you can test yourself by inspecting the execution plans. If id is the clustered index, you should see an ordered clustered index …
C# database access, Dapper, SQL and POCOs – programming design
Let’s say we have a table in SQL represented in C# like this: public class Product { public int ID { get; set; } public string Name { get; set; } public string Picture { get; set; } // …
sql update multiple rows with subselect
I am trying to copy the corresponding graduation_date values from the graduation_term table into the rows in the user_education_mba_school table that have the matching graduation_term_id. Here is my …