Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Starting Member

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 and store it in @i_userid
-if no, then
-set @i_userid = max and add +1 to it to get the new
-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 = 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 +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 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

Flowing Fount of Yak Knowledge

6065 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:

Be One with the Optimizer
Go to Top of Page
  Previous Topic Topic Next 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.08 seconds. Powered By: Snitz Forums 2000