logo
down
shadow

Sql Server Nested Inserts possible


Sql Server Nested Inserts possible

By : user2953645
Date : November 21 2020, 01:01 AM
this one helps. This should do the trick, you can use the APPLY operator to unpivot a table.
code :
create table #tobeinserted
(
    ID int,
    FName varchar(50),
    SName varchar(50), 
    DOB date,
    Response1 varchar(50), 
    Description1 varchar(50),
    Response2 varchar(50),
    Description2 varchar(50),
    Response3 varchar(50),
    Description3 varchar(50)
);

create table #persons
(
    ID int,
    FName varchar(50),
    SName varchar(50), 
    DOB date
);

create table #personsRelations
(
    PersonId int,
    Response varchar(50),
    Description varchar(50)
);

insert into #tobeinserted (ID,FName,SName,DOB,Response1,Description1,Response2,Description2,Response3,Description3)
    values (3,'Bill','John','20140101','Yes','Fault',NULL,NULL,NULL,NULL),
           (4,'Cat','Bill','20140101','Yes','FaultX','Emer','FaultYX','Zeber','Nuhgt');


insert into #persons (id,fname,sname,dob)
select id+6000000, fname, sname, dob
from #tobeinserted

insert into #personsRelations (PersonId, Response, Description)
select t.id+6000000, a.response, a.description
from #tobeinserted t
cross apply
(
    values(Response1,Description1),(Response2,Description2),(Response3,Description3)
) as a(response, description)
where a.response is not null

select * from #persons;
select * from #personsRelations;

drop table #personsRelations;
drop table #persons;
drop table #tobeinserted;


Share : facebook icon twitter icon
Perl - CodeGolf - Nested loops & SQL inserts

Perl - CodeGolf - Nested loops & SQL inserts


By : rickyeyeko
Date : March 29 2020, 07:55 AM
help you fix your problem I had to make a really small and simple script that would fill a table with string values according to these criteria: , 133 characters - non-strict
code :
use DBI;$d=DBI->connect('DBI:mysql','','',{RaiseError=>1});for$a(0..9){for$b(0..9,'X'){$d->do("insert into table values('$a$b')");}}
use strict;use DBI;my$d=DBI->connect('DBI:mysql','','',{RaiseError=>1});for my$a(0..9){for my$b(0..9,'X'){$d->do("insert into table values('$a$b')");}}
use strict;use DBI;
my $d=DBI->connect('DBI:Informix:stores','','',{RaiseError=>1});
foreach my $a (0..9)
{
    foreach my $b (0..9, 'X')
    {
        $d->do("insert into table values('$a$b')");
    }
}
create table table(code char(2) not null);
use strict;
use DBI;
my $d=DBI->connect('DBI:mysql','','',{RaiseError=>1});
my $h=$d->prepare("insert into table(code)values(?)");
foreach my $a (0..9)
{
    foreach my $b (0..9, 'X')
    {
        $h->execute("$a$b");
    }
}
use strict;use DBI;my$d=DBI->connect('DBI:mysql','','',{RaiseError=>1});my$h=$d->prepare("insert into table(code)values(?)");for my$a(0..9){for my$b(0..9,'X'){$h->execute("$a$b");}}
Slow INSERTs from SQL Server to MySQL Linked Server

Slow INSERTs from SQL Server to MySQL Linked Server


By : Sharad
Date : March 29 2020, 07:55 AM
To fix this issue Here's part of the problem...
# Provider: Microsoft OLE Provider for ODBC Drivers
Rails Nested form inserts nulls

Rails Nested form inserts nulls


By : Alice Crawley
Date : March 29 2020, 07:55 AM
hop of those help? The issue ended up being an update to rails from 3.2.5 to 3.2.6. I think it's due to our use of class inheritance for the sole purpose of sharing the asset relationship. We rolled it back and we'll re-examine the relationship at a future time.
Tackling nested inserts using functions

Tackling nested inserts using functions


By : Boogie Fuller
Date : March 29 2020, 07:55 AM
wish helps you One way to approach this is to create a view on your three tables that shows all columns from all three tables that can be inserted or updated. If you then create an INSTEAD OF INSERT trigger on the view then you can manipulate the view contents as if it were a table. You can do the same with UPDATE and even combine the two into an INSTEAD OF INSERT OR UPDATE trigger. The function that your trigger calls then has three INSERT statements that redirect the insert on the view to the underlying tables:
code :
CREATE TABLE shop (
  id serial PRIMARY KEY,
  nm text,
  ...
);

CREATE TABLE shopbranch (
  id serial PRIMARY KEY,
  shop integer NOT NULL REFERENCES shop,
  branchcode text,
  loc text,
  ...
);

CREATE TABLE shopproperties (
  id serial PRIMARY KEY,
  shop integer NOT NULL REFERENCES shop,
  prop1 text,
  prop2 text,
  ...
);

CREATE VIEW shopdetails AS
  SELECT s.*, b.*, p.*
  FROM shop s, shopbranch b, shopproperties p,
  WHERE b.shop = s.id AND p.shop = s.id;

CREATE FUNCTION shopdetails_insert() RETURNS trigger AS $$
DECLARE
  shopid integer;
BEGIN
  INSERT INTO shop (nm, ...) VALUES (NEW.nm, ...) RETURNING id INTO shopid;
  IF NOT FOUND
    RETURN NULL;
  END;
  INSERT INTO shopbranch (shop, branchcode, loc, ...) VALUES (shopid, NEW.branchcode, NEW.loc, ...);
  INSERT INTO shopproperties(shop, prop1, prop2, ...) VALUES (shopid, NEW.prop1, NEW.prop2, ...);
  RETURN NEW;
END; $$ LANGUAGE plpgsql;

CREATE TRIGGER shopdetails_trigger_insert
  INSTEAD OF INSERT
  FOR EACH ROW EXECUTE PROCEDURE shopdetails_insert();
Mongodb nested inserts

Mongodb nested inserts


By : Vyom
Date : March 29 2020, 07:55 AM
To fix this issue You have to do an update on your user document, and specify that you want to $push a new sub-document to the favouriteapi array.
code :
var updatedocument = {
    "api_id" : "sanket",
    "api_name" : "sanket"
};

db.user.update(
  {"email": "ram@ram.com"},
  {$push: {
      "favouriteapi" : updatedocument
    }
  }
);
Related Posts Related Posts :
  • SQL Server Compact stored procedure with multiple values in 1 input
  • How to validate the ICCID number of a SIM card in TSQL?
  • how to calculate all previous datas sum of a sql column on a date range report
  • How to create view listing all friendship for "friend1,friend2" table in T-SQL and prevent inserting duplicate
  • Sum of multiple column in SQL Server
  • Check month and day lies between two dates
  • How would I configure Effort Testing Tool to mock Entity Framework's DbContext withOut the actual SQL Server Database up
  • While looping through a function, Error: Maximum stored procedure, function, trigger, or view nesting level exceeded (li
  • Collapsing records with adjacent start and end dates
  • SQL Server Management Studio 2008 - Timeout Expired error
  • Insert date from VB to SQL Server
  • How to find what table foreign key is from?
  • Deterministic way of getting WeekEnding (Sun) for given date column (for use in computed column)
  • SQL Server, why does one order by query work with a string, but not with an integer?
  • How do I install a SQL Server on the hosted build agent in Visual Studio Online?
  • EXECUTE AS/REVERT within a transaction in SQL Server
  • Distinct 2 field AS one column SQL SERVER
  • how to create a new database after a trigger fired from a table
  • How to sort string alphabetically
  • Checking data in one column in a temp table to a column in another table
  • What's wrong with my IF/ELSE? "ELSE: Incorrect syntax near 'ELSE'."
  • CASE CLAUSE IN WHERE CONDITION
  • TSQL - Creating a running total of a column
  • Why am I getting not null here?
  • Why does sp_refreshview raise an exception on views that are not schema bound?
  • EXEC parameters from a SELECT
  • SQL Server Compact connection
  • Star Schema Structure - To many Dimensions
  • sort utf string in sql server with join clause
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org