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
 Adding a new field

Author  Topic 

atmonline
Starting Member

14 Posts

Posted - 2008-07-01 : 13:06:56
I have a table that list a set of candidates applying for jobs.i need to create an user account for each applicant. once the a/c is created it is used in multiple tables.how can i have that user stored along with the the applicants so that i don't have to qury the a/c table each time i need the userid.

Sheet1 (List of applicants)
-------------------------------
appkey name addres etc,....

1 Thomas 2435 w
2 Mathew 526 e
3 Jacob 6789 we

I have given a sample of code that i have used to create the useraccount and the masterfile for all users


user a/c table ---- js_userdef (jobseekerid is the userid(autogenerated)
masterfile table --- js_masterefile


In js_userdef table i am storing the rownumber with some prefix as password for the identification of records


SELECT
ROW_NUMBER() OVER (ORDER BY Appkey) Number ,
sheet1.*
INTO #sheet1 FROM sheet1

-- now on #sheet1 means sheet1...

SELECT @count=0
WHILE (@count < @ApplicantCount)
BEGIN
SELECT @count = @count + 1
SELECT @Passcode = @Prefix + cast(@count as varchar(10))
EXEC temp_newuser @Passcode
END
-- new users added to js_userdef is now complete



-- Add MasterFrofile for all records in the sheet1 table


--Find the Total no: of records in Masterfile

DECLARE @total_masterapplicants INT
SELECT @total_masterapplicants =coalesce(max(masterprofileid),0)FROM JS_Masterprofile

INSERT INTO JS_MasterProfile
(
JS_UserID,
EmployerID,
FirstName

)
SELECT
(SELECT JobSeekerID FROM JS_UserDef WHERE JS_Password = @Prefix + cast(Number as varchar(10))) JobSeekerID,
793,
[First Name]
FROM
#sheet1



Here i am getting the jobseekerid from the js_userdef. i need to store them along with the #sheet1

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-01 : 13:49:04
Can you explain with some data? you're telling you insert from js_userdef but using #sheet1 instead. didnt understand what you're trying to do here.
Go to Top of Page

atmonline
Starting Member

14 Posts

Posted - 2008-07-01 : 14:05:03
To insert into masterfile i need the js_userid which i am getting from js_userdef. the list of the fields i am inserting from sheet1

sheet1

appkey name etc..
1 abcd
100 xyz
213 pqr


#sheet1
-------
rownumber appkey name etc..
1 1 abcd
2 100 xyz
3 213 pqr






js_userdef
---------
jobseekerid js_username js_passwrod

1 abcd abcd1
2 xyz abcd2
3 pqr abcd3


here i can link js_usrdef with #sheet1 using js_password(abcd+rownumber) and row number

i need to have the joobseekerid from each applicant along with other
data in #sheet1.so each time i need to acces the js_userdef for that. if i can store the jobsskerid along with the temp table(#sheet1) i can avoid that and improve performance.



Basically my question is how to add an extra column in temp table.

select column1,sheet1.* inot #sheet1 from sheet1

Here column1 is not defined in sheet1.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-01 : 14:12:13
quote:
Originally posted by atmonline

To insert into masterfile i need the js_userid which i am getting from js_userdef. the list of the fields i am inserting from sheet1

sheet1

appkey name etc..
1 abcd
100 xyz
213 pqr


#sheet1
-------
rownumber appkey name etc..
1 1 abcd
2 100 xyz
3 213 pqr






js_userdef
---------
jobseekerid js_username js_passwrod

1 abcd abcd1
2 xyz abcd2
3 pqr abcd3


here i can link js_usrdef with #sheet1 using js_password(abcd+rownumber) and row number

i need to have the joobseekerid from each applicant along with other
data in #sheet1.so each time i need to acces the js_userdef for that. if i can store the jobsskerid along with the temp table(#sheet1) i can avoid that and improve performance.



Basically my question is how to add an extra column in temp table.

select column1,sheet1.* inot #sheet1 from sheet1

Here column1 is not defined in sheet1.




what you could do is to put a new column with NULL value when you create sheet1 for jobseekerid and there after update it with the id generated in js_userdef so that from then on you can directly access id from sheet1

some thing like:-

SELECT 
ROW_NUMBER() OVER (ORDER BY Appkey) Number ,
sheet1.*,NULL AS jobseekerid
INTO #sheet1 FROM sheet1

---- now on #sheet1 means sheet1...

SELECT @count=0
WHILE (@count < @ApplicantCount)
BEGIN
SELECT @count = @count + 1
SELECT @Passcode = @Prefix + cast(@count as varchar(10))
EXEC temp_newuser @Passcode
END
-- new users added to js_userdef is now complete

UPDATE s
SET s.jobseekerid=j.jobseekerid
FROM #sheet1 s
INNER JOIN js_userdef j
on j.js_passwrod=s.name+cast(rownumber as varchar(5))
Go to Top of Page

atmonline
Starting Member

14 Posts

Posted - 2008-07-01 : 14:26:08
Thanks
Go to Top of Page
   

- Advertisement -