Showing posts with label statement. Show all posts
Showing posts with label statement. Show all posts

Thursday, March 29, 2012

Granting UPDATE for only certain columns in a table

I have tried using the SQL statement shown below to grant UPDATE permissions for a single column in a single table to a user with db_datareader privileges.

grant update (col_1) on trs.dbo.table_1 to calc

When I then run a SQL script that has an UPDATE for col_1 on trs.dbo.table_1, I get an error message

Msg 230, Level 14, State 1, Line 2100

UPDATE permission denied on column 'col_2' of object 'table_1', database 'TRS', schema 'dbo'.

Why is the error message referring to "col_2" when my SQL statement is trying to update "col_1"?

When I performed the "grant" I did it with an account that has db_owner, db_securityadmin, and db_ddladmin privileges.

This worked in SQL Server 2000. What must I do to get it to work in SQL Server 2005?

Sorry Dan - can you show us the update query?|||

You are going to have to dig deeper. The only scenario that I can think of where an update to another column causes an update to another column causing issues like this is with a trigger with dynamic SQL (a real no-no in almost all cases, but it could exist). The fact that you have appended database names to the ddl makes me curious as to how that *might* cause issue, but I don't even see how anything cross-database could be an issue either.

Here is a script that shows what I am meaning:

create table test
(
column1 int,
column2 int
)
go
create user fred without login
go
execute as user = 'fred'
go
update test
set column1 = 1
/*
Msg 229, Level 14, State 5, Line 1
The UPDATE permission was denied on the object 'test', database 'tempdb', schema 'dbo'.
*/
go
revert
go
grant update (column1) on test to fred
go
execute as user = 'fred'
go
update test
set column1 = 1
/*
(0 row(s) affected)
*/
update test
set column2 = 1
/*
Msg 230, Level 14, State 1, Line 1
The UPDATE permission was denied on the column 'column2' of the object 'test', database 'tempdb', schema 'dbo'.
*/
go
revert
go
create trigger test$updateColumn1
on test
after update
as
begin
exec('
update test
set column2 = 2')
end
go
execute as user = 'fred'
go
update test
set column1 = 1
/*
Msg 230, Level 14, State 1, Line 2
The UPDATE permission was denied on the column 'column2' of the object 'test', database 'tempdb', schema 'dbo'.
*/

If you could post a full example like this showing your issue I think that you might find your error, or certainly one of us can help you out.

|||

Thanks for your support.

Here is a small bit of code that is able to produce the problem. It seems to be associated with having a JOIN in the UPDATE statement. An UPDATE without the JOIN works just fine.

Using a DB_OWNER account perform the following table creation, insert, and grant commands:

create table trs.dbo.people
(
name varchar(10),
sex varchar(10),
age smallint
)

insert into people values ('tom', 'male', 10)
insert into people values ('jane', 'female', 18)
insert into people values ('sue', 'female', 22)

create table trs.dbo.grads
(
name varchar(10),
grad_yr varchar(4)
)

insert into grads values ('jane', '2006')
insert into grads values ('sue', '2002')

grant update (age) on trs.dbo.people to calc

Then, from the db_datareader account, calc, run the following UPDATE statements, one at a time.

update p
set age = 40
from trs.dbo.people p
where (age is not null)
;

update p
set age = 35
from trs.dbo.people p
inner join trs.dbo.grads g
on p.name = g.name
where (age is not null)
;

The first one works. The second one fails with error message

Msg 230, Level 14, State 1, Line 1

UPDATE permission denied on column 'name' of object 'people', database 'TRS', schema 'dbo'.

Does this help?

|||Very nice. I have no answer as to why this is, but I will check around and let you know.|||Thanks!|||Do you have select permission on the other columns?

I know it's complaining that you don't have UPDATE permission... but it's complaining about your access to another column that's involved in the join.

Rob|||

Rob,

If I enter SELECT statements against the two tables, while connected as "CALC", all the rows from each table are returned.

select * from grads;

select * from people;

I have also tried using the DB_OWNER connection to explicity GRANT SELECT access to those tables, and still get the same error message when I try to update the AGE column, as in the example above, while connected as "CALC".

grant select on trs.dbo.people to calc
grant select (name) on trs.dbo.people to calc
grant select on trs.dbo.grads to calc

Dan

|||Ok, so that idea wasn't right. ;)

It's somehow related to the fact that you're joining the table you're updating to another table, and the engine thinks that it needs to be able to update that column too. It doesn't of course, but the fact that the column is used in the query must be confusing it somehow.

I assume this works just fine if you grant update access to the name column too?

One workaround might be to wrap it up in a table expression, but if that works, it'll just be down to luck.

Rob|||

The same code runs just fine with SQL Server 2000. I only ran into a problem when I tried moving it over to SQL Server 2005.

If I grant UPDATE access on the NAME column, as identified in the Error message, then the code runs.

But I hate to do that, since CALC is supposed to be a relatively "unprivileged" user, with db_datareader general privileges only, and CREATE TABLE privileges -- and in my actual application, these other columns are the PRIMARY KEY columns in the tables.

Adding a new column to the table, a column to which CALC has UPDATE permission, was a way of avoiding creating an entirely new table for CALC to own, with 500,000 rows, and a 20-byte primary key that incorporates 5 columns. Had I created such a new table my processing queries would have to JOIN this table to the 500,000 row counterpart. Instead of such a JOIN I added a new column as a simpler, faster solution.

Dan

|||Hmm... I'll have to do some more hunting. I'd like to say "try using a cte or view", or something like that (based on the fact that you might be able to update a view without it thinking it needs to be able to update the joining column), but I actually don't know if that will help. I'll have to recreate the situation locally and try some things.

But hopefully some of the other guys will already know the answer to this.

Rob|||

This seems like such a "natural" thing to have to do, in most any application that requires user permissions to only certain columns in a table.

Consider a table that connects salary to social security number. If you want to allow someone to edit SALARY, must you also allow them to edit SOCIAL SECURITY NUMBER?

What if you are running a medical office and have some sort of PATIENT NUMBER in the medical records. If you want to edit information on their account, such as their ZIP CODE, must you also allow them to edit the PATIENT NUMBER?

Is there maybe a greater need in SQL Server 2005 to create a new ROLE for every different set of permissions that one might need in the database, rather than use GRANT UPDATE to customize access to different users?

I'm not now at my office where I could try it, but I'm wondering if some SYSTEM table stores UPDATE permissions, and if a user has NOT received GRANT or DENY UPDATE permissions on a column in a table, maybe an INNER JOIN is being used, rather than an OUTER JOIN on the permissions table. If that is true, I suppose I can DENY UPDATE on the NAME column in the example, and the query should work, because it finds an entry in the permissions table for the NAME column, even though that entry is "DENY." So tomorrow at the office I'll try DENY UPDATE (name) on TRS.DBO.PEOPLE to CALC. (I'll have to check the syntax on the DENY statement. I think I noticed one in the past few days.)

Dan

|||

This is almost clearly a bug that I posted here: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=257897

A (not terribly satisfying) workaround is to move the join to a subquery:

update p set age = 35
from trs.dbo.people p
where p.name in (select p2.name
from trs.dbo.people p2
inner join trs.dbo.grads g
on p.name = g.name
where (age is not null))

Here is the simple repro with users I posted:

create database trs
go
use trs
go
create table trs.dbo.people
(
name varchar(10),
sex varchar(10),
age smallint
)

insert into people values ('tom', 'male', 10)
insert into people values ('jane', 'female', 18)
insert into people values ('sue', 'female', 22)

create table trs.dbo.grads
(
name varchar(10),
grad_yr varchar(4)
)

insert into grads values ('jane', '2006')
insert into grads values ('sue', '2002')
go
create user calc without login
sp_addrolemember 'db_datareader','calc'
go
grant update (age) on trs.dbo.people to calc
go

--Then, from the db_datareader account, calc, run the following UPDATE
statements, one at a time.
execute as user = 'calc'
go

update p
set age = 40
from trs.dbo.people p
where (age is not null)
;

update p
set age = 35
from trs.dbo.people p
inner join trs.dbo.grads g
on p.name = g.name
where (age is not null)
;

/*
Msg 230, Level 14, State 1, Line 1
The UPDATE permission was denied on the column 'name' of the object
'people', database 'trs', schema 'dbo'.
*/
--

|||

Louis,

Thanks for posting that to the MS "feedback" site.

I tried my "DENY UPDATE" idea, but it didn't fix anything: the same error message was obtained for the same UPDATE statement.

There aren't many places in my code where I am performing updates on columns where the GRANT UPDATE permission is limited to certain columns -- maybe a few dozen. I'll just make the code edits corresponding to your suggestion, and maybe un-do them if/when a patch occurs.

Thanks again.

Dan

|||

Louis,

I reworked my code for SQL Server 2005, using the technique you suggested (or something quite similar):

update p set age = 35
from trs.dbo.people p
where p.name in (select p2.name
from trs.dbo.people p2
inner join trs.dbo.grads g
on p.name = g.name
where (age is not null))

In all but a single instance, this solution worked just fine.

In the remaining instance, the value that I need for the SET clause is from the JOINed table. Were we using the example I supplied (rather than my actual code), this could appear as

update p
set age = cast(g.grad_yr as int) + 18 - 2006
from trs.dbo.people p
inner join trs.dbo.grads g
on p.name = g.name
where (age is not null)

I didn't see any easy way around this, other than to create a CURSOR on "select distinct GRAD_YR from GRADS" and using a LOOP over the CURSOR values, and having code like

update p
set age = @.grad_yr + 18 - 2006
from trs.dbo.people p
where (age is not null) and p.name in (select distinct name from trs.dbo.grads where grad_yr = @.grad_yr)

I am thankful that the number of values for my CURSOR is less than 10, in my actual application.

If you can think of a better alternative, I would be happy to learn of it.

Thanks.

Dan

Granting Permissions on Multiple Tables

I created a new Role called GRPSELECT. I want to give this group the abilit
y to only run the SELECT statement on all the tables in my database. Right
now I can run "GRANT SELECT ON table TO GRPSELECT" in Query Analyzer, but it
only allows me to do this
to one table at a time.
How can I accomplish this to all 600 tables in the database without manually
typing in every single table?
Thanks in advance!Instead of creating a new role you can add these users/group to
db_datareader fixed db role.
Members of db_datareader fixed db role have select permissions on any
objects in the db.
Thanks,
Lyudmila Fokina
Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only
Disclaimer: This posting is provided "AS IS" with no warranties, and confers
no rights.
"Jon Jones" <Jon Jones@.discussions.microsoft.com> wrote in message
news:96F7208A-EA64-467A-8AD2-5477782ED32E@.microsoft.com...
> I created a new Role called GRPSELECT. I want to give this group the
ability to only run the SELECT statement on all the tables in my database.
Right now I can run "GRANT SELECT ON table TO GRPSELECT" in Query Analyzer,
but it only allows me to do this to one table at a time.
> How can I accomplish this to all 600 tables in the database without
manually typing in every single table?
> Thanks in advance!|||Jon,
You can use Transact-SQL to generate the script for you:
Ex:
SELECT 'GRANT SELECT ON ' + so.name + ' TO GRPSELECT'
FROM dbo.sysobjects so
WHERE so.type = 'u'
This output can then be copied.
Randy Dyess
"Jon Jones" wrote:

> I created a new Role called GRPSELECT. I want to give this group the ability to o
nly run the SELECT statement on all the tables in my database. Right now I can run
"GRANT SELECT ON table TO GRPSELECT" in Query Analyzer, but it only allows me to do
thi
s to one table at a time.
> How can I accomplish this to all 600 tables in the database without manual
ly typing in every single table?
> Thanks in advance!sql

Granting permissions

How can I do
create proc MyProc
as
--...proc logic
go
grant execute on MyProc to MYCOMPUTER\ASPNET
I can do the 'grant' statement where the user name doesn't include a
computer prefix - but the ASPNET account does! It keeps complaining, citing
'Incorrect syntax near \'.
The following doesn't work either.
grant execute on MyProc to 'MYCOMPUTER\ASPNET'
Any suggestions?Bonj,
I think MYCOMPUTER\ASPNET is the login name, What is the user name
associated to this login in your db?
AMB
"Bonj" wrote:

> How can I do
> create proc MyProc
> as
> --...proc logic
> go
> grant execute on MyProc to MYCOMPUTER\ASPNET
> I can do the 'grant' statement where the user name doesn't include a
> computer prefix - but the ASPNET account does! It keeps complaining, citin
g
> 'Incorrect syntax near '.
> The following doesn't work either.
> grant execute on MyProc to 'MYCOMPUTER\ASPNET'
>
> Any suggestions?|||assuming MYCOMPUTER\ASPNET is a defined login, then:
grant execute on MyProc to "MYCOMPUTER\\ASPNET"
note double quotes
"Bonj" <Bonj@.discussions.microsoft.com> wrote in message
news:C4F7742C-22E5-4FEB-BE1B-3570FC0645B0@.microsoft.com...
| How can I do
|
| create proc MyProc
| as
| --...proc logic
| go
| grant execute on MyProc to MYCOMPUTER\ASPNET
|
| I can do the 'grant' statement where the user name doesn't include a
| computer prefix - but the ASPNET account does! It keeps complaining,
citing
| 'Incorrect syntax near \'.
| The following doesn't work either.
| grant execute on MyProc to 'MYCOMPUTER\ASPNET'
|
|
| Any suggestions?sql

Tuesday, March 27, 2012

GRANT statement and Windows login

I am trying to grant a Windows login rights to run a Profiler trace.
I'm using the following command:
GRANT ALTER TRACE to 'DOMAIN\User'
but I keep getting the error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'DOMAIN\User'.
I've tried it without the quotes and still get an error.
What am I missing?
ThanksNever mind, I figured it out:
GRANT ALTER TRACE to [DOMAIN\User]sql

GRANT statement and Windows login

I am trying to grant a Windows login rights to run a Profiler trace.
I'm using the following command:
GRANT ALTER TRACE to 'DOMAIN\User'
but I keep getting the error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'DOMAIN\User'.
I've tried it without the quotes and still get an error.
What am I missing?
ThanksNever mind, I figured it out:
GRANT ALTER TRACE to [DOMAIN\User]

'GRANT SELECT ON sysprocesses TO PUBLIC' does not work in SQL 2005

'GRANT SELECT ON sysprocesses TO PUBLIC'
This statement used to work in SQL 7.0 and 2000.
But due to changes in security in SQL 2005 I receive
Server: Msg 4610, Level 16, State 1, Line 1
You can only grant or revoke permissions on objects in the current database.
I am currently on master DB. So I do not understand the error message.
'sysproceses' is a sytem view, in the sys schema.
Objects created in SQL 2005 belong to schemas.
In SQL 2000, sysprocesses is a system table ans objects belong to owner.
Any idea?
Best regards
AlexCT
You should post this in the 2005 beta newsgroups
Bert

'GRANT SELECT ON sysprocesses TO PUBLIC' does not work in SQL 2005

'GRANT SELECT ON sysprocesses TO PUBLIC'
This statement used to work in SQL 7.0 and 2000.
But due to changes in security in SQL 2005 I receive
Server: Msg 4610, Level 16, State 1, Line 1
You can only grant or revoke permissions on objects in the current database.
I am currently on master DB. So I do not understand the error message.
'sysproceses' is a sytem view, in the sys schema.
Objects created in SQL 2005 belong to schemas.
In SQL 2000, sysprocesses is a system table ans objects belong to owner.
Any idea?
Best regards
AlexCTYou should post this in the 2005 beta newsgroups
Bert

'GRANT SELECT ON sysprocesses TO PUBLIC' does not work in SQL 2005

'GRANT SELECT ON sysprocesses TO PUBLIC'
This statement used to work in SQL 7.0 and 2000.
But due to changes in security in SQL 2005 I receive
Server: Msg 4610, Level 16, State 1, Line 1
You can only grant or revoke permissions on objects in the current database.
I am currently on master DB. So I do not understand the error message.
'sysproceses' is a sytem view, in the sys schema.
Objects created in SQL 2005 belong to schemas.
In SQL 2000, sysprocesses is a system table ans objects belong to owner.
Any idea?
Best regards
AlexCTYou should post this in the 2005 beta newsgroups
Bert

Monday, March 26, 2012

GRANT Permission to Users

I need to grant EXEC permission to several users on my Procedures. I would
like to to do this in One GRANT statement. this doesn't run. What do I need
to change.
GRANT EXEC ON
--Proc_Clear_data_CAS_ODS
--Proc_Clear_data_CMS_ODS
--Proc_Clear_data_GAS_ODS
--Proc_load_data_ShipperDim
--Proc_load_data_capacityGrpDim
--Proc_load_data_CAS_To_ODS
--Proc_load_data_CMS_To_ODS
--Proc_load_data_ContractDim
--Proc_load_data_CMS_To_ODS
--Proc_load_data_GAS_To_ODS
--Proc_load_data_PayerDim
--Proc_load_data_pointGrpDim
--Proc_load_data_ShipperDim
TO USER 1
USER 2
USER 3
WITH GRANT OPTION
Hi,
You can not give multiple procedure names in a Grant statement. But the
otherway is possible,
Exexute previlage on a single procedure to multiple users.
Grant exec on proc1 to usr1,ur2,usr3
Thanks
Hari
MCDBA
"baaul" wrote:

> I need to grant EXEC permission to several users on my Procedures. I would
> like to to do this in One GRANT statement. this doesn't run. What do I need
> to change.
> GRANT EXEC ON
> --Proc_Clear_data_CAS_ODS
> --Proc_Clear_data_CMS_ODS
> --Proc_Clear_data_GAS_ODS
> --Proc_load_data_ShipperDim
> --Proc_load_data_capacityGrpDim
> --Proc_load_data_CAS_To_ODS
> --Proc_load_data_CMS_To_ODS
> --Proc_load_data_ContractDim
> --Proc_load_data_CMS_To_ODS
> --Proc_load_data_GAS_To_ODS
> --Proc_load_data_PayerDim
> --Proc_load_data_pointGrpDim
> --Proc_load_data_ShipperDim
> TO USER 1
> USER 2
> USER 3
> WITH GRANT OPTION

GRANT Permission to Users

I need to grant EXEC permission to several users on my Procedures. I would
like to to do this in One GRANT statement. this doesn't run. What do I need
to change.
GRANT EXEC ON
--Proc_Clear_data_CAS_ODS
--Proc_Clear_data_CMS_ODS
--Proc_Clear_data_GAS_ODS
--Proc_load_data_ShipperDim
--Proc_load_data_capacityGrpDim
--Proc_load_data_CAS_To_ODS
--Proc_load_data_CMS_To_ODS
--Proc_load_data_ContractDim
--Proc_load_data_CMS_To_ODS
--Proc_load_data_GAS_To_ODS
--Proc_load_data_PayerDim
--Proc_load_data_pointGrpDim
--Proc_load_data_ShipperDim
TO USER 1
USER 2
USER 3
WITH GRANT OPTIONHi,
You can not give multiple procedure names in a Grant statement. But the
otherway is possible,
Exexute previlage on a single procedure to multiple users.
Grant exec on proc1 to usr1,ur2,usr3
Thanks
Hari
MCDBA
"baaul" wrote:
> I need to grant EXEC permission to several users on my Procedures. I would
> like to to do this in One GRANT statement. this doesn't run. What do I need
> to change.
> GRANT EXEC ON
> --Proc_Clear_data_CAS_ODS
> --Proc_Clear_data_CMS_ODS
> --Proc_Clear_data_GAS_ODS
> --Proc_load_data_ShipperDim
> --Proc_load_data_capacityGrpDim
> --Proc_load_data_CAS_To_ODS
> --Proc_load_data_CMS_To_ODS
> --Proc_load_data_ContractDim
> --Proc_load_data_CMS_To_ODS
> --Proc_load_data_GAS_To_ODS
> --Proc_load_data_PayerDim
> --Proc_load_data_pointGrpDim
> --Proc_load_data_ShipperDim
> TO USER 1
> USER 2
> USER 3
> WITH GRANT OPTION

Grant Permission Statement

Can I use the Grant Statement to grant permissions to all tables in a
database.
I can only get this to work on individual tables?Simply add the user to the db_datareader role:
sp_addrolemember 'db_datareader', 'MyUser'
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:ugLANg1nGHA.2264@.TK2MSFTNGP04.phx.gbl...
Can I use the Grant Statement to grant permissions to all tables in a
database.
I can only get this to work on individual tables?|||Hi
SELECT 'GRANT SELECT ON [' + USER_NAME(uid) + '].[' + name + '] TO '
+
'[MyUser]'
FROM sysobjects
WHERE
type = 'U'
AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(USER_
NAME(uid)) + '.' +
QUOTENAME(name)), 'IsMSShipped') = 0
Copy-Paste the output into the QA and run it against a database
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:ugLANg1nGHA.2264@.TK2MSFTNGP04.phx.gbl...
> Can I use the Grant Statement to grant permissions to all tables in a
> database.
> I can only get this to work on individual tables?
>
>|||In 2005 you can do:
USE dbname
GRANT SELECT ON DATABASE::dbname TO UsrName
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:ugLANg1nGHA.2264@.TK2MSFTNGP04.phx.gbl...
> Can I use the Grant Statement to grant permissions to all tables in a data
base.
> I can only get this to work on individual tables?
>
>

Grant Permission Statement

Can I use the Grant Statement to grant permissions to all tables in a
database.
I can only get this to work on individual tables?Simply add the user to the db_datareader role:
sp_addrolemember 'db_datareader', 'MyUser'
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:ugLANg1nGHA.2264@.TK2MSFTNGP04.phx.gbl...
Can I use the Grant Statement to grant permissions to all tables in a
database.
I can only get this to work on individual tables?|||Hi
SELECT 'GRANT SELECT ON [' + USER_NAME(uid) + '].[' + name + '] TO ' +
'[MyUser]'
FROM sysobjects
WHERE
type = 'U'
AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(USER_NAME(uid)) + '.' +
QUOTENAME(name)), 'IsMSShipped') = 0
Copy-Paste the output into the QA and run it against a database
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:ugLANg1nGHA.2264@.TK2MSFTNGP04.phx.gbl...
> Can I use the Grant Statement to grant permissions to all tables in a
> database.
> I can only get this to work on individual tables?
>
>|||In 2005 you can do:
USE dbname
GRANT SELECT ON DATABASE::dbname TO UsrName
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:ugLANg1nGHA.2264@.TK2MSFTNGP04.phx.gbl...
> Can I use the Grant Statement to grant permissions to all tables in a database.
> I can only get this to work on individual tables?
>
>

Friday, March 23, 2012

GRANT error in SQL 2005: GRANT SELECT ON sysprocesses TO PUBLIC

The following GRANT statement used to work in SQL 7.0 and 2000, but due to
security enhancements in SQL 2005, it does not work anymore.
GRANT SELECT ON sysprocesses TO PUBLIC
I receive the message:
Msg 4610, Level 16, State 1, Line 2
You can only grant or revoke permissions on objects in the current database.
I have just installed SQL 2005 Beta 3, connected as 'sa' and I have not
modified any security at all in SQL 2005.
Does anybody knows how can I make it work?
And what are the changes in SQL 2005 Security?
If you can send info about it it would be great.
Best regardsTry USE <DBNAME> before executing the grant.
"Alex CT" <AlexCT@.discussions.microsoft.com> wrote in message
news:9F313976-07F1-4099-9A31-ED58153979C2@.microsoft.com...
> The following GRANT statement used to work in SQL 7.0 and 2000, but due to
> security enhancements in SQL 2005, it does not work anymore.
> GRANT SELECT ON sysprocesses TO PUBLIC
> I receive the message:
> Msg 4610, Level 16, State 1, Line 2
> You can only grant or revoke permissions on objects in the current
database.
> I have just installed SQL 2005 Beta 3, connected as 'sa' and I have not
> modified any security at all in SQL 2005.
> Does anybody knows how can I make it work?
> And what are the changes in SQL 2005 Security?
> If you can send info about it it would be great.
> Best regards|||I dont know but I am very curious about where you got Beta 3 ?
Chris
Alex CT wrote:
> The following GRANT statement used to work in SQL 7.0 and 2000, but
due to
> security enhancements in SQL 2005, it does not work anymore.
> GRANT SELECT ON sysprocesses TO PUBLIC
> I receive the message:
> Msg 4610, Level 16, State 1, Line 2
> You can only grant or revoke permissions on objects in the current
database.
> I have just installed SQL 2005 Beta 3, connected as 'sa' and I have
not
> modified any security at all in SQL 2005.
> Does anybody knows how can I make it work?
> And what are the changes in SQL 2005 Security?
> If you can send info about it it would be great.
> Best regards

Grant Access Error

SQL Server returns an error when I try go grant privileges to a username
containing '.' (dot). The statement goes like this:
GRANT <privileges> on <table_name> TO gh.om
The error message point to the '.' Is there a workaround?
We use the format "sitename"."username" on quite a lot of
serverconfigurations in our company and it will be quite a job to change al
l
the logon ids.
Thanks for any assistance
/Leif S
--
Systems AnalystUse brackets as delimiters:
GRANT <privileges> on <table_name> TO [gh.om]
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Leif S" <LeifS@.discussions.microsoft.com> wrote in message
news:39A5D87F-9801-4013-87CF-FD6A729AEF47@.microsoft.com...
SQL Server returns an error when I try go grant privileges to a username
containing '.' (dot). The statement goes like this:
GRANT <privileges> on <table_name> TO gh.om
The error message point to the '.' Is there a workaround?
We use the format "sitename"."username" on quite a lot of
serverconfigurations in our company and it will be quite a job to change
all
the logon ids.
Thanks for any assistance
/Leif S
--
Systems Analyst|||Thanks, Tom! Problem solved.
/Leif S.
--
Systems Analyst
"Tom Moreau" wrote:

> Use brackets as delimiters:
> GRANT <privileges> on <table_name> TO [gh.om]
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> ..
> "Leif S" <LeifS@.discussions.microsoft.com> wrote in message
> news:39A5D87F-9801-4013-87CF-FD6A729AEF47@.microsoft.com...
> SQL Server returns an error when I try go grant privileges to a username
> containing '.' (dot). The statement goes like this:
> GRANT <privileges> on <table_name> TO gh.om
> The error message point to the '.' Is there a workaround?
> We use the format "sitename"."username" on quite a lot of
> serverconfigurations in our company and it will be quite a job to change
> all
> the logon ids.
> Thanks for any assistance
> /Leif S
> --
> Systems Analyst
>

Wednesday, March 21, 2012

grabbing a value from listbox to query database

hello forum,

I need to grab astring value from alist box in from a web form,
and pass it to a sql select command statement where that value is equal to
all values in a database table(sql 2000).

example

zip code list box
33154
33254
84578
85475
35454

selected value is 85475

I am putting that value in a string like this:

dim string_zip as string
string_zip = zip_ListBox.text

Question, how do i pass that value to sql stament, i am using this but does not work.

SqlCommand1 =New SqlCommand("SELECT zip FROM table WHERE zip =string_zip", SqlConnection1)

You should use this

SqlCommand1 =New SqlCommand("SELECT zip FROM table WHERE zip ='" &string_zip &"'", SqlConnection1)

Regards

|||

Actually, you should use this:

SqlCommand1=new sqlcommand("SELECT zip FROM table WHERE zip=@.zip",SqlConnection1)
SqlCommand1.parameters.add(new sqlparameter("@.zip",sqldbtype.varchar))
SqlCommand1.parameters("@.zip").value=string_zip

Using the string concatenation method is a good way to get yourself hacked.

|||

Motley wrote:

Actually, you should use this:

SqlCommand1=new sqlcommand("SELECT zip FROM table WHERE zip=@.zip",SqlConnection1)
SqlCommand1.parameters.add(new sqlparameter("@.zip",sqldbtype.varchar))
SqlCommand1.parameters("@.zip").value=string_zip

Using the string concatenation method is a good way to get yourself hacked.

Yes, this is preferred over my solution becuase it is more secure.

Thanks Motley

|||

Thanks for you help, it works, but I encounter another problem.

Problem:

multiple selection from list box is allowed, I am getting a string value from all selected choices like this:

Dim listofstringsAsString
Dim itemAs ListItem

ForEach itemIn listbox.Items
If item.SelectedThen
listofstrings = listofstrings & item.Text & ","
EndIf
Next

so i havelistofstrings = (selectedvalue1,selectedvalue2,selectedvalue3,......)

I need to select all values from a table in database where any of those values corresponds.

NOTE: Values in database can also be in the format of (value1,value2,value3,.....) or just a single (value1,)

|||

Search for messages on the UDF named "Split" one was posted recently.

SELECT *
FROM table
WHERE field IN (SELECT * FROM Split(@.listofstrings))

OR
SELECT *
FROM table
JOIN Split(@.listofstrings) s ON (table.field=s.id)

Goup by clause confused....

Hi NG,

I have the following problem that I hope you can help me with (MS-SQL server
2000)

Imagine a statement like this:

"select id, firstname, (select top 1 id from testdata) as testid, lastname
from nametable order by firstname"

I would like to have this grouped by "lastname"...I assume that I have to
use the "Group by" clause, but it keeps complaining about id, firstname, etc
not being in the clause...if I just inserts the "Group by lastname" in the
statement above.

How do I group these data?

--
regards,
SummaHi

Your current statement does not make much sense! Without DDL (Create table
statements) and example data (as insert statements) and expected output, it
is hard to know what your really want.

But you may want to try

SELECT n.id, n.Firstname, max(t.id) as TestId, n.lastname
from nametable n JOIN TestData t on n.id = t.id
GROUP BY n.id, n.Firstname, n.lastname

John

"Summa" <summa@.summarium.dk> wrote in message
news:cb3vtu$2v1s$1@.news.cybercity.dk...
> Hi NG,
> I have the following problem that I hope you can help me with (MS-SQL
server
> 2000)
> Imagine a statement like this:
> "select id, firstname, (select top 1 id from testdata) as testid, lastname
> from nametable order by firstname"
> I would like to have this grouped by "lastname"...I assume that I have to
> use the "Group by" clause, but it keeps complaining about id, firstname,
etc
> not being in the clause...if I just inserts the "Group by lastname" in the
> statement above.
> How do I group these data?
> --
> regards,
> Summa|||On Sun, 20 Jun 2004 14:28:51 +0200, Summa wrote:

>Hi NG,
>I have the following problem that I hope you can help me with (MS-SQL server
>2000)
>Imagine a statement like this:
>"select id, firstname, (select top 1 id from testdata) as testid, lastname
>from nametable order by firstname"
>I would like to have this grouped by "lastname"...I assume that I have to
>use the "Group by" clause, but it keeps complaining about id, firstname, etc
>not being in the clause...if I just inserts the "Group by lastname" in the
>statement above.
>How do I group these data?

Hi Summa,

If you use group by, all columns in the select list must either appear in
the group by clause as well, or they must be an aggregation function. This
is the only way to make sure that SQL Server can unambiguously return the
correct results.

If you want to group by lastname, how should SQL Server present it's
results if two rows in nametable have the same lastname? Because of the
group by, only one row may be returned with this lastname - but which id
and firstname should be displayed?

I need to know more about your table structure, data and desired result to
give more specific aid. If you need more help, post the following:
* DDL for the relevant tables (CREATE TABLE statements, including all
relevant constraints),
* Sample data (in the form of INSERT statements),
* And expected output.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hi,

"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:_RfBc.837$2p3.7002158@.news-text.cableinet.net...
> Your current statement does not make much sense! Without DDL (Create table
> statements) and example data (as insert statements) and expected output,
it
> is hard to know what your really want.

Ok? It was just example an statement...but suppose I have this table:

Table n:
id int
firstname ntext
lastname ntext

There are 5 records in that table (listed as id,firstname,lastname):

1 Tom Jensen
2 Arnold Scwarzenegger
3 Clint Eastwood
4 Helen Eastwood
5 Tim Scwarzenegger

My select MUST include a clause on the lastnames that gives me the
opportunity to specify them as a list - like this:

"Select id, firstname, lastname from n where lastname in
('Eastwood','Scwarzenegger') order by firstname"

That gives me the result
2 Arnold Scwarzenegger
3 Clint Eastwood
4 Helen Eastwood
5 Tim Scwarzenegger

But I want this:
3 Clint Eastwood
4 Helen Eastwood
2 Arnold Scwarzenegger
5 Tim Scwarzenegger

That is:
1: Grouped by lastname
2: The lastname specified first in the list-clause is also the
lastname-group that is listed first in the result.

My problems int the above:
1. How to group the data.
2. How to order the groupings (eg: Eastwood group comes.before
Scwarzenegger)
3. My data contains fields that cant be Grouped (ntext)

Hope u know what I mean now :)
--
regards,
Summa|||Hi,

"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:qu2bd099pbssskjdb4jn7oho6ivi67r68f@.4ax.com...

> If you use group by, all columns in the select list must either appear in
> the group by clause as well, or they must be an aggregation function. This
> is the only way to make sure that SQL Server can unambiguously return the
> correct results.

Ok...so if my tables contains ntext fields, I cannot group the data?

> If you want to group by lastname, how should SQL Server present it's
> results if two rows in nametable have the same lastname?

By the "order" clause? In no order if not specified...

Could I get you to see my reply to John Bell? - I have tried to soecify my
problems...:)

--
regards,
Summa|||Hi

Select id, firstname, lastname
from n
where lastname in ('Eastwood','Scwarzenegger')
order by lastname, firstname

Will give

3 Clint Eastwood
4 Helen Eastwood
2 Arnold Scwarzenegger
5 Tim Scwarzenegger

This is not grouped but ordered.

John

"Summa" <summa@.summarium.dk> wrote in message
news:cb45ek$3sl$1@.news.cybercity.dk...
> Hi,
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:_RfBc.837$2p3.7002158@.news-text.cableinet.net...
> > Your current statement does not make much sense! Without DDL (Create
table
> > statements) and example data (as insert statements) and expected output,
> it
> > is hard to know what your really want.
> Ok? It was just example an statement...but suppose I have this table:
> Table n:
> id int
> firstname ntext
> lastname ntext
> There are 5 records in that table (listed as id,firstname,lastname):
> 1 Tom Jensen
> 2 Arnold Scwarzenegger
> 3 Clint Eastwood
> 4 Helen Eastwood
> 5 Tim Scwarzenegger
> My select MUST include a clause on the lastnames that gives me the
> opportunity to specify them as a list - like this:
> "Select id, firstname, lastname from n where lastname in
> ('Eastwood','Scwarzenegger') order by firstname"
> That gives me the result
> 2 Arnold Scwarzenegger
> 3 Clint Eastwood
> 4 Helen Eastwood
> 5 Tim Scwarzenegger
> But I want this:
> 3 Clint Eastwood
> 4 Helen Eastwood
> 2 Arnold Scwarzenegger
> 5 Tim Scwarzenegger
> That is:
> 1: Grouped by lastname
> 2: The lastname specified first in the list-clause is also the
> lastname-group that is listed first in the result.
>
> My problems int the above:
> 1. How to group the data.
> 2. How to order the groupings (eg: Eastwood group comes.before
> Scwarzenegger)
> 3. My data contains fields that cant be Grouped (ntext)
> Hope u know what I mean now :)
> --
> regards,
> Summa|||Hi,

"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:20hBc.902$XS3.7383096@.news-text.cableinet.net...

> Select id, firstname, lastname
> from n
> where lastname in ('Eastwood','Scwarzenegger')
> order by lastname, firstname
> Will give
> 3 Clint Eastwood
> 4 Helen Eastwood
> 2 Arnold Scwarzenegger
> 5 Tim Scwarzenegger
> This is not grouped but ordered.

True, but correct me if Im wrong...this statement will not ensure that the
"Eastwood" listings comes before "Schwarzenegger". It just gives the correct
result because "E" comes before "S" in the alphabet.

Suppose that it wasnt lastnames - lets say we have en extra column in the
previous table. Lets call it "Categoryid". And that id maps to a table
called "Category";

Table category:
id int
Categoryname nvarchar(100)

-and it has these 3 records:

1 Test
2 MoreTest
3 EvenMoreTest

And the "n" table now looks like this:

Table n:
id int
categoryid int
firstname ntext
lastname ntext

Again, there are 5 records in that table (listed as
id,categoryid,firstname,lastname):

1 1 Tom Jensen
2 2 Arnold Scwarzenegger
3 3 Clint Eastwood
4 2 Helen Eastwood
5 3 Tim Scwarzenegger

Now, my sql looks like this:

"select n.id, n.firstname, n.lastname, category.categoryname from n inner
join category on n.categoryid = category.id where category.id in (2,3) order
by firstname"

How would I go about this? What I want is this result:

2 Arnold Scwarzenegger MoreTest
4 Helen Eastwood MoreTest
3 Clint Eastwood EvenMoreTest
5 Tim Scwarzenegger EvenMoreTest

This is:
Ordered with "MoreTest" before "EvenMoreTest" - like in the statement "...in
(2,3)..."

Notice that there might be 10 or 20 numbers in the list - clause. So I cant
rely on the lexical ordering whatsoever :(

--
Regards,
Summa


> John
> "Summa" <summa@.summarium.dk> wrote in message
> news:cb45ek$3sl$1@.news.cybercity.dk...
> > Hi,
> > "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> > news:_RfBc.837$2p3.7002158@.news-text.cableinet.net...
> > > Your current statement does not make much sense! Without DDL (Create
> table
> > > statements) and example data (as insert statements) and expected
output,
> > it
> > > is hard to know what your really want.
> > Ok? It was just example an statement...but suppose I have this table:
> > Table n:
> > id int
> > firstname ntext
> > lastname ntext
> > There are 5 records in that table (listed as id,firstname,lastname):
> > 1 Tom Jensen
> > 2 Arnold Scwarzenegger
> > 3 Clint Eastwood
> > 4 Helen Eastwood
> > 5 Tim Scwarzenegger
> > My select MUST include a clause on the lastnames that gives me the
> > opportunity to specify them as a list - like this:
> > "Select id, firstname, lastname from n where lastname in
> > ('Eastwood','Scwarzenegger') order by firstname"
> > That gives me the result
> > 2 Arnold Scwarzenegger
> > 3 Clint Eastwood
> > 4 Helen Eastwood
> > 5 Tim Scwarzenegger
> > But I want this:
> > 3 Clint Eastwood
> > 4 Helen Eastwood
> > 2 Arnold Scwarzenegger
> > 5 Tim Scwarzenegger
> > That is:
> > 1: Grouped by lastname
> > 2: The lastname specified first in the list-clause is also the
> > lastname-group that is listed first in the result.
> > My problems int the above:
> > 1. How to group the data.
> > 2. How to order the groupings (eg: Eastwood group comes.before
> > Scwarzenegger)
> > 3. My data contains fields that cant be Grouped (ntext)
> > Hope u know what I mean now :)
> > --
> > regards,
> > Summa|||Hi

The Order by clause is documented in books online or at
http://msdn.microsoft.com/library/d...order_by_clause

To order by the category name alphabetically descending use:

select n.id, n.firstname, n.lastname, c.categoryname
from n join category c on n.categoryid = c.id
where c.id in (2,3)
order by c.categoryname desc, n.firstname asc

If you read Books online, you will see that you can order by columns not
specified in the select columns. Therefore if you want to order by ascending
categeory id then

select n.id, n.firstname, n.lastname, c.categoryname
from n join category c on n.categoryid = c.id
where c.id in (2,3)
order by n.categoryid, n.firstname

John

"Summa" <summa@.summarium.dk> wrote in message
news:cb4a74$941$1@.news.cybercity.dk...
> Hi,
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:20hBc.902$XS3.7383096@.news-text.cableinet.net...
> > Select id, firstname, lastname
> > from n
> > where lastname in ('Eastwood','Scwarzenegger')
> > order by lastname, firstname
> > Will give
> > 3 Clint Eastwood
> > 4 Helen Eastwood
> > 2 Arnold Scwarzenegger
> > 5 Tim Scwarzenegger
> > This is not grouped but ordered.
> True, but correct me if Im wrong...this statement will not ensure that the
> "Eastwood" listings comes before "Schwarzenegger". It just gives the
correct
> result because "E" comes before "S" in the alphabet.
> Suppose that it wasnt lastnames - lets say we have en extra column in the
> previous table. Lets call it "Categoryid". And that id maps to a table
> called "Category";
> Table category:
> id int
> Categoryname nvarchar(100)
> -and it has these 3 records:
> 1 Test
> 2 MoreTest
> 3 EvenMoreTest
> And the "n" table now looks like this:
> Table n:
> id int
> categoryid int
> firstname ntext
> lastname ntext
> Again, there are 5 records in that table (listed as
> id,categoryid,firstname,lastname):
> 1 1 Tom Jensen
> 2 2 Arnold Scwarzenegger
> 3 3 Clint Eastwood
> 4 2 Helen Eastwood
> 5 3 Tim Scwarzenegger
>
> Now, my sql looks like this:
> "select n.id, n.firstname, n.lastname, category.categoryname from n inner
> join category on n.categoryid = category.id where category.id in (2,3)
order
> by firstname"
> How would I go about this? What I want is this result:
> 2 Arnold Scwarzenegger MoreTest
> 4 Helen Eastwood MoreTest
> 3 Clint Eastwood EvenMoreTest
> 5 Tim Scwarzenegger EvenMoreTest
> This is:
> Ordered with "MoreTest" before "EvenMoreTest" - like in the statement
"...in
> (2,3)..."
> Notice that there might be 10 or 20 numbers in the list - clause. So I
cant
> rely on the lexical ordering whatsoever :(
> --
> Regards,
> Summa
>
>
>
>
> > John
> > "Summa" <summa@.summarium.dk> wrote in message
> > news:cb45ek$3sl$1@.news.cybercity.dk...
> > > Hi,
> > > > "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> > > news:_RfBc.837$2p3.7002158@.news-text.cableinet.net...
> > > > Your current statement does not make much sense! Without DDL (Create
> > table
> > > > statements) and example data (as insert statements) and expected
> output,
> > > it
> > > > is hard to know what your really want.
> > > > Ok? It was just example an statement...but suppose I have this table:
> > > > Table n:
> > > id int
> > > firstname ntext
> > > lastname ntext
> > > > There are 5 records in that table (listed as id,firstname,lastname):
> > > > 1 Tom Jensen
> > > 2 Arnold Scwarzenegger
> > > 3 Clint Eastwood
> > > 4 Helen Eastwood
> > > 5 Tim Scwarzenegger
> > > > My select MUST include a clause on the lastnames that gives me the
> > > opportunity to specify them as a list - like this:
> > > > "Select id, firstname, lastname from n where lastname in
> > > ('Eastwood','Scwarzenegger') order by firstname"
> > > > That gives me the result
> > > 2 Arnold Scwarzenegger
> > > 3 Clint Eastwood
> > > 4 Helen Eastwood
> > > 5 Tim Scwarzenegger
> > > > But I want this:
> > > 3 Clint Eastwood
> > > 4 Helen Eastwood
> > > 2 Arnold Scwarzenegger
> > > 5 Tim Scwarzenegger
> > > > That is:
> > > 1: Grouped by lastname
> > > 2: The lastname specified first in the list-clause is also the
> > > lastname-group that is listed first in the result.
> > > > > My problems int the above:
> > > 1. How to group the data.
> > > 2. How to order the groupings (eg: Eastwood group comes.before
> > > Scwarzenegger)
> > > 3. My data contains fields that cant be Grouped (ntext)
> > > > Hope u know what I mean now :)
> > > --
> > > regards,
> > > Summa
> >|||On Sun, 20 Jun 2004 16:06:35 +0200, Summa wrote:

>Hi,
>"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
>news:qu2bd099pbssskjdb4jn7oho6ivi67r68f@.4ax.com...
>> If you use group by, all columns in the select list must either appear in
>> the group by clause as well, or they must be an aggregation function. This
>> is the only way to make sure that SQL Server can unambiguously return the
>> correct results.
>Ok...so if my tables contains ntext fields, I cannot group the data?
>> If you want to group by lastname, how should SQL Server present it's
>> results if two rows in nametable have the same lastname?
>By the "order" clause? In no order if not specified...
>Could I get you to see my reply to John Bell? - I have tried to soecify my
>problems...:)

Hi Summa,

You are correct that you can't use ntext columns in group by. But are you
sure you need an ntext columns? They require lots of special handling; not
being able to use them in group by should be the least of your worries.
Are you absolutely sure you need more than 4000 characters??

From your exchange with John Bell, I see that you try to use group by to
achieve ordering. That is not correct. Group by is for grouping.

I'm sorry if I sound harsh, but I think you need to acquire at least a
basic understanding of SQL first. We can help you writing queries, but not
if you lack the basic skills and knowledge. A good starters' book can be
found here:

http://www.amazon.com/gp/reader/020...9057670-0048722

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hi,

"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:5BiBc.975$IZ4.8716484@.news-text.cableinet.net...

> To order by the category name alphabetically descending use:
[Snip]

Somehow I get misunderstood, i'm afraid :(
Im aware of the Order by clause and its use - and if you read my post again
you'll se that this clause isnt what Im after...Notice at the end of my post
it says: "Notice that there might be 10 or 20 numbers in the list - clause.
So I cant rely on the lexical ordering whatsoever" - Or any "order by"
clause...

This is simple:
"select n.id, n.firstname, n.lastname, c.categoryname
from n join category c on n.categoryid = c.id
where c.id in (2,5,8,1,3)
order by c.categoryname desc, n.firstname asc"

The above select statement is going to produce a result that gives me the
listing in categoryid-order 2,5,8,1,3 ? No...of course not.

But thanks for trying anyway.

--
regards,
Summa|||Hi

There is no way to specify a random order like this without using something
like a temporary table or some other means to give it an order.

You can do something like:

select n.id, n.firstname, n.lastname, c.categoryname
from
( SELECT 1 AS id, 2 AS CategoryId
UNION ALL
SELECT 2, 5
UNION ALL
SELECT 3, 8
UNION ALL
SELECT 4, 1
UNION ALL
SELECT 5, 3 ) D join N ON n.categoryid = D.id
JOIN category c ON D.id = c.id
ORDER BY D.id, n.firstname

John

"Summa" <summa@.summarium.dk> wrote in message
news:cb4nel$nat$1@.news.cybercity.dk...
> Hi,
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:5BiBc.975$IZ4.8716484@.news-text.cableinet.net...
> > To order by the category name alphabetically descending use:
> [Snip]
> Somehow I get misunderstood, i'm afraid :(
> Im aware of the Order by clause and its use - and if you read my post
again
> you'll se that this clause isnt what Im after...Notice at the end of my
post
> it says: "Notice that there might be 10 or 20 numbers in the list -
clause.
> So I cant rely on the lexical ordering whatsoever" - Or any "order by"
> clause...
> This is simple:
> "select n.id, n.firstname, n.lastname, c.categoryname
> from n join category c on n.categoryid = c.id
> where c.id in (2,5,8,1,3)
> order by c.categoryname desc, n.firstname asc"
> The above select statement is going to produce a result that gives me the
> listing in categoryid-order 2,5,8,1,3 ? No...of course not.
> But thanks for trying anyway.
> --
> regards,
> Summa|||Summa (summa@.summarium.dk) writes:
> Ok? It was just example an statement...but suppose I have this table:
> Table n:
> id int
> firstname ntext
> lastname ntext

Permit me to bump in and point out that ntext is highly unsuitable for
name columns. Use nvarchar(50) or somesuch.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

goto Statement in DTS ?

Hello,

Can anyone plz tell me how to use GoTo statement in DTS packages ?

Thanks in advance !

I dont think goto stmt works in DTS !

goto Statement in DTS ?

Hello,

Can anyone plz tell me how to use GoTo statement in DTS packages ?

Thanks in advance !

I dont think goto stmt works in DTS !

GOTO problem

I get the following error when I try and use a GOTO statment with my abel at the bottom of the script:

[[A GOTO statement references the label 'ENDSCRIPT' but the label has not been declared.]]

My code structure is as follows:

Some code here

SET NOCOUNT OFF

SELECT * FROM PERSON_STAGE1 WHERE PERSONUID
IN (SELECT PERSONUID FROM PRO_SING_QA_26923_AMMAR..PERSONUID)

IF @.@.ROWCOUNT > 1
BEGIN
PRINT '*** ERROR: SCRIPT ENDING BECAUSE OF DUPLICATE UID'
GOTO ENDSCRIPT
END

SET NOCOUNT ON

.
.
.
.
.
ENDSCRIPT:

when I execute my code I get the error message mentioned above. Any suggestions?

Thanks in advance.hi,

your script (as much as you have posted) works fine in my enviroment !

markus

Monday, March 19, 2012

Got it to work....well partially

Hello everyone, I had a previous issue with if...then....etc statement, but I got it to work, so thats a good thing. The only problem is that it works only when i have a single line displaying, if its more than 1, it dont work any ideas why?

My report is table, broken into 2 groups, one by department, then by last name. My thought is the Sum(Fields!AMT_EARNED.Value) still giving me issues.....but I dont know....

=iif(((Fields!SumHRS.Value * 7.5) > Sum(Fields!AMT_EARNED.Value)),((Fields!SumHRS.Value * 7.5) - Sum(Fields!AMT_EARNED.Value)), 0)

Abner

p.s here is a picture of it.

http://i200.photobucket.com/albums/aa195/abz_26/Gotittowork.partially.jpg?t=1186176038

Nevermind........got it

|||tubular?

that's like so awesome dude