|
Hi,
Any one suggest me how to write a sql query to execute the following.
I am having three tables as show below:
Table 1:
EmpID Name
1 aaa
2 bbb
3 ccc
Table 2:
SalID EmpID DesigID Salary
1 1 000000 000000
2 3 000000 000000
Table 3:
DesigID SalID DesigID Left
1 1 000000 false
2 2 000000 True
In the above i have to get the SalID,Salary details, based on the below condition
1. Based on the EmpId
2. The DesigID from table 3 should be retireved, but that DesigID should not be presented in Table 2(only those rows not presented in table 2 should be retrieved from table 3) based on the DesigID in both tables, also with one more condition.
3.Also i have to retrieve the rows from table 3 if the boolean value is true based on the SalID.
Am i clear with the above process? If no please kindly excuse me.
Any one please suggest me
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
how to get columns of table in order of their ordinal position instead of
alphabetical order of column name?
cn.GetSchema("Columns", restrictions)
output: column_name ordinal_position
...........ambit...............3
...........noise...............1
...........z...................2
required output: column_name ordinal_position
....................noise...............1
....................z...................2
....................ambit...............3
|
|
|
|
|
I want the columns of table in order of their ordinal position.
is it possible?
|
|
|
|
|
exec sp_columns '[table name]'
If that's too much info then you could try:
SQL 2000
SELECT o.name, c.name as columnname FROM syscolumns c
INNER JOIN sysobjects o ON o.id = c.id
WHERE o.[name] = 'reports'
ORDER BY c.colorder
SQL 2005
SELECT O.name, C.name as columnname FROM sys.columns C
INNER JOIN sys.objects O ON O.object_id = C.object_id
WHERE O.[name] = 'reports'
ORDER BY c.column_id
|
|
|
|
|
Thank You Mark. It Works. Well Done.
|
|
|
|
|
i m planning to create a job site,so plz guide me for design the database,tables in sqlserver 2005
|
|
|
|
|
If you can't design the tables are you sure you are competent enough to create a complete web site?
Try reading up on the subject rather than asking someone to do your work for you.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
AbhishekAgarwal15 wrote: so plz guide me for design the database,tables in sqlserver 2005
Well - I'd start by gathering requirements, working out what fields need to be in the database and then normalize it to at least third normal form. Here's a technical hint for you - consider investing in some paper and pencils for your design.
|
|
|
|
|
You need to do alot of planning, investigation and searching (on the web). If you don't know how to design the database and tables I agree with the other person find out for yourself. You'll get alot more satisfaction if you've done the work yourself. Trust me I know!
Kris MCP
|
|
|
|
|
Hi All,
I wanted to go for the OCP. Can any one please let me know How many exams I have to give? Which are the exams and the fees structure? And from where I can give this exam and how to pay the fees of the exams. I wanted to do OCP in 9i or 11i.
Thanks,
RK
|
|
|
|
|
Have you tried looking on the Oracle web site? I bet they have loads of information about OCP
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi, I have the following problem,
I have 2 different databases for 2 seperate systems I some of the data in db 2 is needed in db 1, I want to create an sql trigger for ms sql 2000 that will run when ever an update happens in db 2 the fields that I want in db 1 from db 2 must update with the changes made in db 2.
So my problem is in the trigger how to I get the values that where updated into the update stament I want to send to the other database
CREATE TRIGGER tr_table_UPDATE
ON dbo.vehicle_db1.Vechicle_list
FOR UPDATE
AS
Update dbo.vehicle_db2.Vechicles set Registration_No = 'PYS 789 GP', Model = 'Data from the original update' where ID = 'id from original update'
I hope this makes sense, in a way its kinda replication.
Thank in adavance.
|
|
|
|
|
If the databases are on the same server then there is no need to replicate the tables because you can reference tables using:
select * from <database>.<owner>.<table> If the databases are on separate servers, but have reliable connectivity then consider using "linked servers" (look them up in BOL).
Otherwise consider using "replication" (look it up in BOL).
Hope that helps.
Andy
|
|
|
|
|
thanks man, but thats not what I need, i will have redesign the entire package if I am to go that route this is supposed to be a quick fix, I know its not ideal, but I figured it out about an hour ago thanks.
|
|
|
|
|
I have a table having columns like values, like this
col1 col2 col3
1000 10 2
1000 20 3
1000 30 4
2000 10 5
2000 20 6
2000 30 7
3000 10 8
3000 20 9
3000 30 10
I want to fetch records like if i enter col2 as 20 and col1 as 1500 then
with
"SELECT col3 FROM table1 WHERE col2 = @col2"
I will get 3 rows having respective records of value 20 for col2(col2 values are fixed)
but col1 values are variable i.e. can fall into different ranges like 1400,1500,2300 etc.
but col2 values are fixed
I want to return only one row for eg. col2 as 20 and col1 as 1500
then
1000 20 3
this row should get returned
How can i do this?
I don't know how to use cursors...
|
|
|
|
|
salon wrote: I don't know how to use cursors...
Any problem for searching and learning how it works ?
|
|
|
|
|
No issues to learn...
I am just asking is there anyone have idea to do it in optimized way?
as I am trying
col1 have variable inputs like 1200,1300,2100 etc...
and col2 have fixed inputs
I am doing like this calculating min and max values for col1
and trying to put col2 in that range
but till I m not able to achieve...
|
|
|
|
|
There's no problem in using a cursor within a while loop -> have a look at the MSDN, to review the example and you'll have your're problem solved.
|
|
|
|
|
i have a date format in 06/01/2008 which datatype is nvarchar(50).how i will change it into 06/jan/2008 format in sql. Plz help me.
select log_in_date from test1
out_put
06/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
06/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
07/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
08/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
09/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
10/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
11/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
12/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
13/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
14/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
15/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
16/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
17/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
18/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
19/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
20/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
21/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
22/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
23/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
24/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
25/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
26/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
27/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
28/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
29/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
30/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
31/01/2008
|
|
|
|
|
mon***z wrote: nvarchar(50).
I am not sure about NVarchar, but if you were using DateTime type, use convert function to change the display format.
|
|
|
|
|
thanks man for your answer
I missed the namespace
<br />
Messagebox.show("Invalid Data Entry");<br />
<br />
ANd the message Messagebox, does not Exists in the Current Context
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Well, a couple of sample dates would have done rather than dozens, but your answer is:
Using @a to represent your column
<br />
declare @a nvarchar(50)<br />
set @a = '28/10/2008'<br />
set dateformat dmy<br />
select convert(varchar,datepart(day,@a)) + '/' + left(datename(month,@a),3) + '/' + convert(varchar,datepart(year,@a))
You need the set dateformat dmy so SQL knows its day month year
Bob
Ashfield Consultants Ltd
|
|
|
|
|
actually i have five columns like system,name,qty,weight,area
I have to fetch the details from database. I have to write a query where i have to multiply qty and weight and put it in weight column and at the same time i have to display the records in the descending order of total weight . How can this be done. Please help
skd
|
|
|
|
|
It's a home work question, how about this
SELECT
[system]
,[name]
,[qty] * [weight] As TotalWeight
FROM
[dbo].[TestTable]
ORDER BY
TotalWeight DESC
|
|
|
|
|
Hi there,
I'm looking for some advise for a generic data fetch pattern for IDataReader I'm working on, as follow:
// main load
using(GenericDataReader reader = new GenericDataReader(cm.ExecuteReader()))
{
while (reader.Read())
{
orders.Add(reader.Get<Order>()); // "GetList" pattern
//return new Order(reader); // "Get" pattern
}
}
// generic reader; interface implementation removed
public class GenericDataReader : IDataReader
{
// ... \\
public T Get<T>(string name)
{
int i = _dataReader.GetOrdinal(name);
if (_dataReader.IsDBNull(i))
return default(T);
else
return (T)_dataReader.GetValue(i);
}
public T Get<T>() where T : ILoadable, new()
{
T entity = new T();
entity.Load(this, false);
return entity;
}
}
// All business objects must implements this interface
public interface ILoadable
{
void Load(GenericDataReader reader, bool deep);
}
// Sample business object
class Order : ILoadable
{
int id;
Customer customer; // Note
DateTime orderDate;
DateTime requiredDate;
DateTime? shippedDate;
List<OrderDetail> orderDetails;
public Order(){ }
public Order(GenericDataReader reader)
{
Load(reader, true);
}
#region ILoadable Members
public void Load(GenericDataReader reader, bool deep)
{
id = reader.Get<int>("OrderID");
customer = reader.Get<Customer>(); // Note
orderDate = reader.Get<DateTime>("OrderDate");
requiredDate = reader.Get<DateTime>("OrderRequiredDate");
shippedDate = reader.Get<DateTime?>("OrderShippedDate");
if (deep && reader.NextResult())
{
orderDetails = new List<OrderDetail>();
while (reader.Read())
{
orderDetails.Add(reader.Get<OrderDetail>());
}
}
}
#endregion
}
What do you think? Are there any major drawback with this model I'm missing? Are there any more clever way to do that?
I really appreciate your time reading this. Thanks in advance,
Rubens
|
|
|
|