Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Difficult Query-Big help

Author  Topic 

leite333
Starting Member

8 Posts

Posted - 2011-08-02 : 01:28:27
Hi i want some help with a complicate query.
I have 3 tables
In one table (51) with columns Code,Name,Tel
In second table(16) CodeName (same with code from 51) and Description,Customer
In third table(01) CodeCustomer,Customer,Names (same with Name from 51)
Now whats is the wrong. The user put a new entry at table 51. And change an old one entry at 01 with the new one.

For example gives at (51) 003,Test,23400
So within the program that user use at table 01 the changes work and
Names become from Test1(with code 001)->Test
but in the table 16 it keeps the old record at CodeName (001) and dont get the new one(003)
So what i want to do is.. With the query get the last record from 51 and more right get only the last Code(same with CodeName). Look at table 01 in wich Customers is the new code and then replace at table 16 the old one code with new one.
I hope i didnt confuse you....
We can solve it step by step..like first how i will get the last code from table 51 and second how i can search at table 01 where exist???

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-02 : 02:24:57
sorry not clear from your explanation. can you explain with a data sample to clarify what you're trying to achieve?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

leite333
Starting Member

8 Posts

Posted - 2011-08-03 : 01:27:39
Ok Here an example.....
Table 01:(Customers)
CustomerId Company NameSeller
001 George Test Soros
002 Albert Red Soros
003 Nick Blue White

Table 51:(Sellers)
CodeSeller NameSeller Tel
00001 Soros Nick 1234567
00002 White Maria 2345678

Table 16:(Receipts)
CodeCustomer CustomerDescription CodeRe DeReceipt SellerId
001 George Test 123 TDA 00001
002 Albert Red 124 TDA 00001
003 Nick Blue 125 TDA 00002
001 George Test 030 APD 00001

Now the same columns are: CodeCustomer=01.Customer
CustomerDescription=01.Company
SellerId=51.CodeSeller

Question:
The user make a new record at table 51 -> 00003 Melina Zack 4875847
Then the user change the at table 01 the seller at customer 003 Nick Blue with new one seller (00003) Melina Zack
At table 01 everything is ok. But at table 16 at third row the old code of seller 00002 remains and i want to change with new one 00003
So as i thinking it i think the last row of 51 that user insert have to keep it at memory compare at 01 in what customers exist and then make the changes with the new code seller at 016
I dont know if this can work with update...Do i need any function to search and compare at table 01????
Help please...Any other ideas?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-03 : 01:31:18
what all will be available as input from user? does user pass the customerid of customer whose seller is to be updated from 51?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

leite333
Starting Member

8 Posts

Posted - 2011-08-03 : 02:47:20
user can input sellers at table 51 with new codes
and also user can change the seller at table 1
its software program that database is behind....
Go to Top of Page
   

- Advertisement -