.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
satyapriyanayak
SP
abhays
Clintonzz
mattyclown
Post New Web Links

How to INSERT new row values from two different sources, all fields from a table plus one additional

Posted By:      Posted Date: September 26, 2010    Points: 0   Category :Sql Server
 
--Loading the single row returned by a table valued function into a temp table works fine like this:
DECLARE @techNumLoop VARCHAR(25)

DECLARE @myTemp TABLE (
 Names Varchar(25)
,Item_Count Integer
,Expense_AP MONEY
--,[...20 more fields]
)
--Loop a while
INSERT @myTemp SELECT * FROM ufn_FindSomeRow(@techNumLoop)
--And finally display a table with one row for each function call
SELECT * FROM @myTemp
============
--My Question: what if I would like to also display the value of @techNumLoop passed in to ufn_FindSomeRow?
--Then I add a field to @myTemp to hold it:
DECLARE @myTemp TABLE (
 TechNum VARCHAR(25)--added


View Complete Post


More Related Resource Links

How to insert values into my table the data is coming from inline table valued function

  
Hi all,   i have table oi want insert values into my table the data is coming from inline table valued function how i can use the inline table valued function to insert datainto my table i have inline function which out puts 3 collumns of data how i can insert this data into my table i have the insert statment like below insert into tablename(c1,c2,c3,c4,c5) select ('abc',....................,'xyz') how i can use the out put put of my inline function to  to insert data into my columns c2,c3,c4. please help me out Thanks & Regards Sunil Yoganna

How do I insert values into different colunms but same row in a table using stored procedure

  
Hi everyone, I wish to create a scenario whereby my Stored Procedure will be able to do an Insert values into two colunms but single row of a table. For instance: AS BEGIN INSERT INTO Table1 (Message1, Number1) VALUES(@Message1, @Number1) END When I do the above stored procedure using SQL Express, and Excecute the stored procedure in VS2005 C# using ADO.Net, the table is updated but the values of Message1 and Number1 are inserted into different rows i.e. when value is inserted into Message1, Number1 is '0' and vice-versa. what I really want is for both Message1 and Number1 to be inserted with values at the same row. How do I acheive this please? Many thanks in advance.

How do I insert values into different colunms but same row in a table using stored procedure

  
Hi everyone, I wish to create a scenario whereby my Stored Procedure will be able to do an Insert values into two colunms but single row of a table. For instance: AS BEGIN INSERT INTO Table1 (Message1, Number1) VALUES(@Message1, @Number1) END When I do the above stored procedure using SQL Express, and Excecute the stored procedure in VS2005 C# using ADO.Net, the table is updated but the values of Message1 and Number1 are inserted into different rows i.e. when value is inserted into Message1, Number1 is '0' and vice-versa. what I really want is for both Message1 and Number1 to be inserted with values at the same row. How do I acheive this please? Many thanks in advance.

insert mulitple comma seperated values in a temp table

  
I have a reporting services report with a single parameter that can take up to 10 numbers which are comma delimited. I need to insert those numbers into a temp table with one column. So if the numbers were 1 - 10 I would expect to see something like this if querying the temp table Acct_Num 1 2 3 4 5 6 7 8 9 10 Is there a way to do this insert into the table using a comma delimeted string of numbers? ThanksFJK

Insert checkboxlist selected values into sql table using createuser wizard

  

Hi,

I am using CreateUserWizard control where I collect personal information from the user on the first step (ie. name, address, tel, mobile etc) then on the second step I collect information for membership service (ie. user name, password, email etc). When user clicks Create button, information is sent to two different tables in the same database. Everything works fine but one.

In the first step where I collect personal information, I also collect details about Interest which is a CheckBoxList (CheckBoxList is getting values from Interests table: 1-White, 2-Green, 3-Brown, 4-Maroon, 5-Yellow).

What I want to do is, when client selects his itnerest categories and clicks Create button, to send selected values from CheckBoxList into the third table called Categories. I want values to be registered into the CatCode column in Interests table as comma delimited. For example: if client selected "White", "Green" and "Yellow", appropriate values for those interests (such as 1, 3, 5) to be registered under Categories table CatCode column (like: 1,3,5).

Following is my code:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
        oncreateduser="CreateU

Deleted Values Insert into a New Table

  
Hi All,

I have Database DB and Table CB ..CB has 3  dependent Tables OB ,CP,CI
So My Requirement is ..

delete  From CB
where ID_NUM not Like '99%'

But here delete will  not work because of FK .. so i need to delete records from OB CP CI Tables first ...and I need to store all the Deleted Records of all the 4 Tables (CB,OB,CP,CI) in a seperate Table
May be all 4 deleted values in a Table
or
each table deleted records in each Seperate newly created table..



all i Know to go each child table and delete but ....It may be time Running Script ...
Or
Individuall for Each delete and Store in new table



Can any one Help me on This .....


display / insert values by comparing 2 columns of a table

  

hi

i have a table which has the following columns 

A_ID, A_Value,A_Date,B_ID,B_Value_B_Date

 

i have another table as follows

A_ID,B_ID,A_Value,B_Value, Date

 

this is to be done 

* if A_date and B date are equal, one record shoould be entered to the TABLE 02. the values should be A_ID,B_ID,A_Value_B_Value and A_Date (since the date is equal, no problem; even can insert B_Date instead of A_Date)

* if A_Date and B_Date are different, then the following should happen

insert one record to TABLE02 as A_ID,B_ID, A_Value, 0 , A_Date

insert another record to TABLE02 as A_ID,B_ID, 0 , B_Value, B_Date

 

(As you can see, when the date differs we enter the single record of Table 01 into 2 recoerds in table 02. the Value column and Date column are related in such a way that when A's date is entered, the value for B should be 0 and vise versa..)

 

i tried having a UDF but in halfway remembered that we cannot include INSERTS in UDFs..

can anyone please explain me how can i solve this problem ??

 

PS: For your reference , i've sketched a diagram. please click on this link to view it for further clarifications

http://i54.tinypic.com/eq6p7t.png

 

thanks in advance

-novicedba :)


Inserting Values from Multiple Sources into One Table

  

Hi, I'd like to insert a single integer value from tables on multiple databases into a single table row that includes the date. Any ideas on how to structure this query? (Each value represent a distinct count of user names that have used an application for a given day. The log tables are located on multiple databases).

Right now I have an INSERT INTO statement that inserts the date and a count from a single source into a row, but I'm having trouble understanding how to insert the values from all sources into a single row with one query? UNION? Not sure...

Any advice would be greatly appreciated.


Insert value using Table Value Functions

  
a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

How to deal with NULL values in a SQL table

  

 Hi all

In order to add/update/delete data from a table I build 2 classes: 1 class containing all the table fields and another class with methods to add/insert/update/delete records. I am learning how to avoid errors when your table must use SQL NULL values. One error is when I call my UPDATE method (see below):

  public void UpdateItem(OcItemConstraintDetails item)
 {
  SqlConnection con = new SqlConnection(connectionString);
  SqlCommand cmd = new SqlCommand("ItemConstraints_Update", con);
  cmd.CommandType = CommandType.StoredProcedure;

  cmd.Parameters.Add(new SqlParameter("@itemConstraintId", SqlDbType.Int, 4));
  cmd.Parameters["@itemConstraintId"].Value = item.ItemConstraintId;

  cmd.Parameters.Add(new SqlParameter("@path", SqlDbType.NVarChar, 150));
  cmd.Parameters["@path"].Value = item.Path;
...

if you watch the SQL profiler trace you will see that I am passing a value of 'default' ;so that causes me problems.

exec ItemConstraints_Update @itemConstraintId=1,@path=default


With that said, what are the best practices when your SQL table accepts NULL values and when:
- you are passing an empty value to your stored procedure;

Model Binding the values in an HTML Table back to Controller / Model

  

Currently, I am working with ASP.NET MVC1 and am still learning about Model Binding and how values from a View are passed back to the Controller / Model. Specifically, I want take an existing Model, create a Table and populate the Rows of the Table, allow the user to edit some fields and pass it back.

In my example, I have a Class called "Ingredient" which has 4 public accessors:  Name, Barcode, Amount, and Unit

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcACE.DomainModel.Entities.Ingredient>>" %>

<% using (Html.BeginForm("SubmitOrder","MyController"))
{ %>

<table>
<tr>
<th>Name</th>
<th>Barcode</th>
<th>Amount</th>
<th>Unit</th>
</tr>
<% if (Model != null)
{
foreach (var item in Model)
{ %>
<tr>
<td><%= Html.Encode(item.Name)%></td>
<td><%= Html.Encode(item.Barcode)%></

How to access the refrenced table fields in Ilist object of table MVC asp.net

  

Hello,

I have 2 tables, master, detail. 1.master table have fields (id, username, plan)-->id is primary key (PK) 2. detail table have fields (srNo,id, worksummary, ... )--> srNo is PK.

I have created foreign key relationship from detail to .master table for "id" field.

the code is:

IList<detail> objDetail=new List<detail> (); 
IList<master> objMaster = new List<master> ();
string[] sarray = queryFields.Split('|');//

for (int i = 0; i < sarray.Length; i++)
{
string[] sfields = sarray[i].Split(',');

if (sfields[0] != "")
{

objDetail.Add(new _detail { Id = count , modify = sfields[1].ToString(), verified = sfields[2], I});


}
}

I have problem to add fields in "objDetail" using Add method. But I am unable to access the reference field "Id" , rest of the field of detail table can be accessed using objDetail.

How can I access the "Id" field from objDetail object to add in IList.

I want to solve this problem


hsdsd: how to insert two values from text box1 to gridview g

  

database:a

table a

a                                 b

jhgd                           kljhskjd

sdghdshgd                 jkhdjhdjk

what i need is when enter some values(varchar ) in txt 1 and 2

it should be added in database and shown in gridview1 after i press butt1

 

any bodyknows full code answer/akdj


Need to add value to table on insert

  

Hi,

I'm fairly new to .NET.  I need to add values CreatedBy, CreatedDate, ModifiedBy, ModifiedDate to the record before inserting it to the database. 

Please see code below. 

     [MetadataType (typeof(GRIPSMetaData))]
    public partial class SchoolDistrict
    {
        internal void OnSaving(ChangeAction changeAction)
          {
            if (changeAction == ChangeAction.Insert)
            {
              this.CreatedBy = 5;
              this.CreatedDate = DateTime.Now;
            }
            else if (changeAction == ChangeAction.Update)
            {
                this.CreatedBy = 5;
          &nb

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend