In your example, a Credit Card can be owned by one and only one person at a time, therefore a bridge table would not be required. A bridge table is required only in a many-to-many relationship.
There is nothing it TSQL (Microsoft SQL Server "Transactional SQL") that is going to automatically insert foreign key values. You might have used some tool that created TSQL for you, but then it generated TSQL which explicitly inserted the key value.
If you want to vary the table name dynamically then you must use dynamic SQL. There is no alternative. Either sp_executesql or 'execute' can be used. Are you sure it needs to be dynamic though?
Jun Du wrote:
create a table on the master databse:
You need to learn to create your own database and then tables go in that. And once you do delete everything that you created in 'master'.
Can't tell exactly what's wrong but you seem to have too many joins. That cross join... hmmm... I am nos sure what you want to do. Personally, I would use a union operator to duplicate records.
SELECT a.col1, a.col2,... 0 As Flag
FROM myTable a
WHERE ...
UNION
SELECT b.col1,b.col2,... 1 as Flag
FROM myTable b
WHERE ....
Suppose I have a calculated field for age computed from dob and the current date. If this field is not updated and you query someone's age, it will return incorrect results. For example, if the query returns someone's [current] age as 64 when it should have been 65, the result would be incorrect.
Check the following query... SELECT T1.empcode,T1.[basic Salary],B.Bonus,T.Transport FROM Table1 T1 INNER JOIN (SELECT Amount As Bonuus, empcode FROM Table2 WHERE Additions = 'Bonus') B ON B.empcode = T1.empcode INNER JOIN (SELECT Amount AS Transport, empcode FROM Table2 WHERE Additions = 'Transport') T ON T.empcode = T1.empcode Adjust the inner join to left join if required... Thanks
Your code is using an implicit equijoin and a cartesianjoin.
WHERE RF.REPAIR_ORD = RH.REPAIR_ORD and Rp.REPAIR_ORD = cg.REPAIR_ORD
For simplicity, let me assume the actual table names are RF, RH, RP and CG. RH and RH are joined and RP and CG are joined but RF is not joined to RP or CG; and also RH is not joined to RP and CG. So the end result is a cartesian product of two equijoins (RF-RH X RP-CG). I would suggest using an explicit join. From your code, I assume that REPAIR_ORD is common to all the tables. So my code would look like
SELECT .....
FROM
RF INNER JOIN RH
ON RF.REPAIR_ORD=RH.REPAIR_ORD
INNER JOIN RP
ON RH.REPAIR_ORD=RP.REPAIR_ORD
INNER JOIN CG
ON RP.REPAIR_ORD=CG.REPAIRD_ORD
WHERE ....
I am using inner joins but depending on what you need, you may find left joins or right joins more suitable.
I haven't tested this but try it .
SELECT TOP 1 @dtLatestDate=dtDateTime, @fltLatestPrice =fltPrice FROM Customers ORDER BY dtDateTime DESC
SELECT TOP 1 @dtEarliestDate =dtDateTime, @fltEarliestPrice=fltPrice FROM Customers ORDER BY dtDateTime ASC
No problem :)
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com
wjbjnr wrote:
I just wanted to know how many different connections at a same time can be made from different computers?
64k. Or some number pretty close to that. There are gotchas for that. 1. They must exist at the same time. 2. The number can be smaller, quite a bit, if the clients are rapidly opening and closing connections. 3. The number can be smaller, specifically 5000, if you have not explicitly updated the MS Windows registry of the server box. This is the maximum and is impacted by 2 above as well. None of that has to do with the database and certainly not tables. It has to do with the IP address. So if you have a computer with more than one real IP Address then each is subject to the same restrictions. See the following http://msdn.microsoft.com/en-us/library/aa560610.aspx[^] Be very careful if you start messing with those values.
I have also tried the various work arounds, non of which have worked after a reboot. I've instructed my users to export the data to PDF and print from there (and disabled the print control). Major Pain...
Common sense is admitting there is cause and effect and that you can exert some control over what you understand.
Hello, I tried with above query.But it extracting 10 Digits.I dont know why.I have some datas in Field4 like this "74_125352" actually i need 125352.
modified on Sunday, May 8, 2011 1:46 AM
i think little bit issue will arise. If you instantiate an object for ten times or create ten object or some method of an object (like,- Open() and Close()) performance can be a issue . mostly its a bad programming practice.