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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 please..... I want code

Author  Topic 

B5CSE
Starting Member

25 Posts

Posted - 2005-05-03 : 14:56:39

I have clients table that contain on the gender field
And this field contain the id of gender 1 and 2 but I have another table(gender1)
Which contain the id of gender and the name of gender male and female

The problem I want transact statement that display all the fields in
Clients table but the gender field display the name of gender in the
Gender1 table not the id of gender which is saved in the clients table

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-05-03 : 15:14:40
Its already May, you should be way past basic joins. Or have you been cutting class?

Are you aware of Books On Line (the online help that comes with Sql Server)? Look up "joins-sql server | From Clause"

Be One with the Optimizer
TG
Go to Top of Page

B5CSE
Starting Member

25 Posts

Posted - 2005-05-03 : 15:20:22
I read but I do not can find the proper code

please help me quickly
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-05-03 : 15:22:57
Don't tell me they're teaching surrogates?



USE Northwind
GO

SET NOCOUNT ON
CREATE TABLE myPhone99 (PhoneID int IDENTITY(1,1), PhoneNumber varchar(10))
CREATE TABLE myLastName99 (LastNameID int IDENTITY(1,1), LastName varchar(50))
CREATE TABLE myFirstName99 (FirstNameID int IDENTITY(1,1), FirstName varchar(10))
CREATE TABLE myGender99 (GenderID int IDENTITY(1,1), Gender varchar(10))

CREATE TABLE myClient99(
ClientID int IDENTITY(1,1)
, PhoneID int
, LastNameID int
, FirstNameID int
, GenderId int)
GO

INSERT INTO myGender99(Gender) SELECT 'Male' UNION ALL SELECT 'Female'
INSERT INTO myFirstName99(FirstName) SELECT 'Brett' UNION ALL SELECT 'Boy5' UNION ALL SELECT 'Tara'
INSERT INTO myLastName99(LastName) SELECT 'Kaiser' UNION ALL SELECT 'CSE' UNION ALL SELECT 'Duggan'
INSERT INTO myPhone99(PhoneNumber) SELECT '9735551212' UNION ALL SELECT '800551212'
GO

INSERT INTO myClient99(PhoneID, LastNameID, FirstNameID, GenderID)
SELECT 1,1,1,1 UNION ALL
SELECT 2,2,2,1 UNION ALL
SELECT 3,3,3,2 UNION ALL
SELECT 4,3,3,2 UNION ALL
SELECT 3,4,3,2 UNION ALL
SELECT 3,4,4,2 UNION ALL
SELECT 3,3,4,4
GO

-- Very useful, huh
SELECT * FROM myClient99
GO

-- Fun with surrogates...

SELECT c.ClientID, p.PhoneNumber, l.LastName, f.FirstName, g.Gender
FROM myClient99 c
LEFT JOIN myPhone99 p ON c.PhoneID = p.PhoneID
LEFT JOIN myLastName99 l ON c.LastNameID = l.LastNameID
LEFT JOIN myFirstName99 f ON c.FirstNameID = f.FirstNameID
LEFT JOIN myGender99 g ON c.GenderID = g.GenderID
GO

SET NOCOUNT OFF
DROP TABLE myPhone99, myLastName99, myFirstName99, myGender99, myClient99
GO




Brett

8-)
Go to Top of Page

B5CSE
Starting Member

25 Posts

Posted - 2005-05-03 : 15:34:28
I am sorry , I forget that sql statement is according to the number
of id of the client
Go to Top of Page

B5CSE
Starting Member

25 Posts

Posted - 2005-05-03 : 17:58:56
I make stored procedure
CREATE PROCEDURE find_id_client
@ID int output,
@genderid int output
AS
DECLARE @ErrorCode int
select * from clients c
left JOIN gender g ON c.GenderID = g.GenderID
where @id=id



SET @ErrorCode=@@ERROR
IF (@ErrorCode = 0)
RETURN (0)
ELSE
RETURN (@ErrorCode)


but on the form the genderid in clients table whem i do run for my form it display the number not the name
Go to Top of Page

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-05-03 : 21:55:39
Would that because the number (id) is 1st in your data grid??

AVOID SELECT *
Use a column list instead!

Andy

Beauty is in the eyes of the beerholder
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-05-03 : 22:05:08
You could always try this link:

http://www.sql-server-performance.com/forum/topic.asp?TOPIC_ID=8231
Go to Top of Page
   

- Advertisement -