Click here to Skip to main content
15,888,967 members
Home / Discussions / Database
   

Database

 
GeneralDate Pin
trilokharry20-Dec-07 17:49
trilokharry20-Dec-07 17:49 
GeneralRe: Date Pin
That's Aragon20-Dec-07 19:24
That's Aragon20-Dec-07 19:24 
GeneralRe: Date Pin
trilokharry21-Dec-07 0:54
trilokharry21-Dec-07 0:54 
GeneralGetting tables from a database Pin
MarkB77720-Dec-07 16:47
MarkB77720-Dec-07 16:47 
GeneralRe: Getting tables from a database Pin
pmarfleet20-Dec-07 21:18
pmarfleet20-Dec-07 21:18 
GeneralRe: Getting tables from a database Pin
Rajkamal_dfine21-Dec-07 19:47
Rajkamal_dfine21-Dec-07 19:47 
NewsSQL Server 2008 virtual training available for ITPros and developers during January Pin
brucedkyle20-Dec-07 13:59
brucedkyle20-Dec-07 13:59 
QuestionCollation Issue When Using PRINT Pin
Tee12320-Dec-07 7:31
Tee12320-Dec-07 7:31 
Can someone help me with 2 issues that I have? My first issue is when I try to print out that the user account exist with the following line: PRINT 'The login ' + @login_name + ' already exists.'
I receive the following error: Server: Msg 446, Level 16, State 8, Line 45
Cannot resolve collation conflict for concatenation operation.
What can I do to solve this?

My second issue is I'm trying to have this procedure work for both Sql 2000 and Sql 2005. I currently using 2000 for testing but in 2005 to create a user login the line of code: --CREATE USER 'username' FOR LOGIN 'loginname' creates a syntax error. Is there anyway around this?

DECLARE @sqlVersion char(2)
DECLARE @login_name char(12)
DECLARE @loginpassword char(12)
DECLARE @username char(12)
DECLARE @dbase char(8)

SET @login_name = loginname
SET @loginpassword = password
SET @username = username
SET @dbase = password

SELECT @sqlVersion = SUBSTRING(CAST(SERVERPROPERTY('productversion') AS char),1,1)

use database
IF NOT EXISTS(SELECT name FROM sysxlogins WHERE name = @login_name)
IF @sqlVersion = 8
BEGIN
EXEC sp_addlogin @login_name, @loginpassword, @dbase
EXEC sp_grantdbaccess @login_name, @username
EXEC sp_addrolemember 'db_datareader', @username
EXEC sp_addrolemember 'db_datawriter', @username
/* Grant the account access to the rms database */
use database
EXEC sp_grantdbaccess @login_name, @username
/* Grant rights to the STORED PROCEDURES */
BEGIN TRANSACTION

USE database
GRANT EXECUTE ON SP TO username
IF @@ERROR <> 0 GOTO err_handler
PRINT '----User was successfully created ----'
COMMIT TRANSACTION
END
ELSE
PRINT 'The login ' + @login_name + ' already exists.'


IF @sqlVersion = 9
BEGIN
EXEC sp_addlogin @login_name, loginpassword, @dbase
--CREATE USER 'opcenteruser' FOR LOGIN 'opcenteruser'
EXEC sp_addrolemember 'db_datareader', @username
EXEC sp_addrolemember 'db_datawriter', @username

use database
EXEC sp_grantdbaccess login_name, @username
EXEC sp_addrolemember 'db_datareader', @username
BEGIN TRANSACTION
/* Grant rights to the STORED PROCEDURES */
USE database
GRANT PERMISSIONS TO STORED PROCEDURES....
IF @@ERROR <> 0 GOTO err_handler
PRINT '----User was successfully created ----'
COMMIT TRANSACTION
END
RETURN
err_handler:
ROLLBACK TRANSACTION
RAISERROR ('Failed to commit transaction.', 16,1)
RETURN

GO
Terrance C.

QuestionParameters to a SQL View? Pin
keniagm20-Dec-07 7:23
keniagm20-Dec-07 7:23 
GeneralRe: Parameters to a SQL View? Pin
pmarfleet20-Dec-07 9:18
pmarfleet20-Dec-07 9:18 
GeneralSQL Query Pin
sandhya1420-Dec-07 1:04
sandhya1420-Dec-07 1:04 
GeneralRe: SQL Query Pin
Ujjaval Modi20-Dec-07 2:00
Ujjaval Modi20-Dec-07 2:00 
GeneralRe: SQL Query Pin
sandhya1423-Dec-07 19:30
sandhya1423-Dec-07 19:30 
GeneralRe: SQL Query Pin
sandhya1423-Dec-07 19:41
sandhya1423-Dec-07 19:41 
GeneralRe: SQL Query Pin
sandhya1423-Dec-07 22:25
sandhya1423-Dec-07 22:25 
Generalinsert query Pin
niki_nilu20-Dec-07 0:08
niki_nilu20-Dec-07 0:08 
GeneralRe: insert query Pin
niki_nilu20-Dec-07 1:46
niki_nilu20-Dec-07 1:46 
General## Temp tables Pin
Bino B19-Dec-07 23:21
Bino B19-Dec-07 23:21 
GeneralRe: ## Temp tables Pin
Pete O'Hanlon19-Dec-07 23:31
mvePete O'Hanlon19-Dec-07 23:31 
GeneralMSSQL: Finding out column names for a table Pin
ruanr19-Dec-07 22:02
ruanr19-Dec-07 22:02 
Generalsolved Pin
ruanr19-Dec-07 22:04
ruanr19-Dec-07 22:04 
QuestionHow to manage SQL Log in SQL 2000 Pin
Sasmi_Office19-Dec-07 21:50
Sasmi_Office19-Dec-07 21:50 
QuestionDisplay Data Month Wise Pin
deepaks319-Dec-07 21:18
deepaks319-Dec-07 21:18 
GeneralRe: Display Data Month Wise Pin
ChandraRam19-Dec-07 22:29
ChandraRam19-Dec-07 22:29 
GeneralRe: Display Data Month Wise Pin
deepaks319-Dec-07 22:34
deepaks319-Dec-07 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.