SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Generic sql script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shawn19801980
Starting Member

USA
1 Posts

Posted - 05/16/2013 :  15:19:35  Show Profile  Reply with Quote
I want to write an generic sql script. I am totally new to SQL

I have the following parameters.

We need to create a generic sql script that will accept the following parameters:

1. @v_Username
2. @v_Encryptedpassword
3. @v_Firstname
4. @v_Lastname
5. @v_Branch
6. @i_Rolekey

Step 1: Add the users row

Check the users table to see if the username already exists
-if yes then get the users.id and store it in @i_userid
-if no, then
-set @i_userid = max users.id and add +1 to it to get the new users.id
-insert the following

INSERT INTO users(id,username,password,first_name,last_name,active,deleted,created_by,dev_access)
values(@i_userid, @v_Username, @v_Encryptedpassword,@v_firstname,@v_lastname,1,0,1,0)

Step 2: Set the branch information

-Set the @i_branchid = bu_entries.id where bu_entries description = @v_Branch
-Set the @v_branchcode = bu_entries.code where bu_entries description = @v_Branch

Check the users_entries table to see if a row already exists for users_entries.user_id = @i_userid and users_entries.entry_id = @i_branchid

IF no then Insert the following

INSERT INTO users_entries (user_id,entry_id,role_id,sort_order,created_Date)
values (@i_userid,@i_branchid,@i_rolekey,1,curdate())

Now do the dar_branch table
- Set the @i_maxdarbranchkey = max dar_branch.id +1

Check to see if the row already exists for dar_branch.userid = @i_userid and dar_branch.branchid = @v_branchcode

If no then insert the row

insert into dar_branch (id,userid,branchid)
values (@i_maxdarbranchkey, @i_userid, @v_branchcode,3)

Step 3: Insert the acl_priviliges rows to allow access to the dar pages by cloning from an existing user. We will need to do a loop to increment the acl_priviliges.id for each insert.

Check first to see if the user exists where acl_privliges.user_id = @i_userid

If no, then we need to insert all the rows

Insert into acl_priviliges (id, resource_id,role_id,user_id,template_id, rule)
Select @i_maxid,resource_id,role_id,@i_userid,template_id,rule from acl_privilges where user_id= 32052

TG
Flowing Fount of Yak Knowledge

USA
5932 Posts

Posted - 05/16/2013 :  17:11:48  Show Profile  Reply with Quote
You didn't actually ask a question so I'm not sure what level of help you're looking for? You're not just handing out assignments, right

Here is a link that describes how to post a question so that anyone here can reply with exactly what you need:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx



Be One with the Optimizer
TG
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000