* 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

More Related Resource Links

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

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.

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.

I found the article below describing this same issue with the Oracle merge statement. It also described a work-around:
http://searchoracle.techtarget.com/tip/Merging-datasets-with-NULL-values
I have been unable to find a solution to this issue for SQL Server 2008. I am trying to do basic ETL from Staging table to a Type II dimension table in a Data Warehouse. I am using the Merge statement with the Unique key minus the modification
date as my merge key list. I have a handful of columns (in both Staging and the DW) containing nulls in my merge key list. I have tried the ISNULL function and the ANSI_NULL db option (OFF) with no success. When I put zeros in the null
columns, it works as expected. I am about to try separate INSERT and UPDATE statements, but I fear that the NULL comparison issue will bite me there with the JOIN statement. Has anyone else experienced this? NULL values are valid in our Data
Warehouse. How can I make T-SQL handle them?
Thank you for your help, Jesse

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

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).

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

--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 whileINSERT @myTemp SELECT * FROM ufn_FindSomeRow(@techNumLoop)
--And finally display a table with one row for each function callSELECT * 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

Update: if records exist in both the table compare them, and update value in destination table if value is different.

Insert: if record doesn't exist in destination table, add new record in destination table.

Delete: if record exist in destination table but not in source table, delete record from destination table.

----> I have created an SSIS package that does all this task but in order to perform delete operation, I have to store all records of destination table into a temporary table.
And since it's not the most efficient way, I have created another SSIS package by using Lookup & conditional Splits
method, now it works fine with inserting and updating information but I am not sure on how to handle removing record operation!

I would really appreciate if you could help me with this.

(In order to archive inserting and deleting records, I have referred following thread!
http://sqlblog.com/blogs/andy_leonard/archive/2007/07/09/ssis-design-pattern-incremental-loads.aspx )

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):

When adding a stored procedure into the Entity Data Model I can select whether the procedure returns a scalar, a (new) complex type or one of the entity types I already defined.

How do I do something similar for a view?

I mean assuming I have a view like this

CREATE VIEW FilteredFoos as SELECT Foo.* FROM Foo join ... WHERE ...

(that is a view that implements some involved filtering, but returns all columns from one table) how do I add it to the project so that I can use the entity set, but get the Foo objects, not some new FilteredFoo objects.