Showing posts with label dbo. Show all posts
Showing posts with label dbo. Show all posts

Friday, March 30, 2012

how to change the data label in SQL?

I have the following SQL statement..

select month(dbo.udfAddUTCBias(start_date_time, 180)) as report_month, direction as direction, count(*) as total_records from traffic with (nolock) where dbo.udfAddUTCBias(start_date_time, 180) >= '2/24/2007' and dbo.udfAddUTCBias(start_date_time, 180) < DateAdd(dd, 1, '2/24/2007') group by month(dbo.udfAddUTCBias(start_date_time, 180)), direction

but the result of the direction field is 1 and 0..

however, I need to show inbound when the result is 0 and outbound when the result is 1 without changing the actual data in the table.

You could use CASE keyword: http://msdn2.microsoft.com/en-us/library/aa258235(SQL.80).aspx

select month(dbo.udfAddUTCBias(start_date_time, 180)) as report_month

, case direction

when 0 then 'inbound'

when 1 then 'outbound'

end

as direction

, count(*) as total_records from traffic with (nolock) where dbo.udfAddUTCBias(start_date_time, 180) >= '2/24/2007' and dbo.udfAddUTCBias(start_date_time, 180) < DateAdd(dd, 1, '2/24/2007') group by month(dbo.udfAddUTCBias(start_date_time, 180)), direction

Monday, March 26, 2012

how to change owner for many tables

sorry to be dumb!
i have a whole bunch of tables with me as owner - i want to make dbo owner.
how?
i just can't find an appropriate mouse click in enterprise manager, and i don't really want the 40 command lines to do it manually.
thanks for ideas, izyNo bulk way that I know of in Enterprise Mangler.

So we are reduced to being deviant... Er, devious. We use a script to write a script!SELECT 'EXECUTE sp_changeobjectowner ''[' + su.name + '].['
+ so.name + ']'', ''dbo'''
FROM dbo.sysusers AS su
JOIN dbo.sysobjects AS so
ON (so.uid = su.uid)
WHERE 'izy' = su.name
ORDER BY so.nameThis will create a script as its output that you can copy into query analyzer, exectute, and go merrily on your way.

-PatP|||big gulp!

Pat - thanks: that's really scary but i'll give it a thrash and see what falls out of the tree.

izy|||purrrrfect.

thanks a lot, izy|||See, it helps to have deviant... Er, devious friends!

Thinking "outside the box" is a bit difficult at first, but the dividends can be huge. I keep wondering "What box?" whenever I hear that phrase though!

-PatP|||See, it helps to have deviant... Er, devious friends!

Thinking "outside the box" is a bit difficult at first, but the dividends can be huge. I keep wondering "What box?" whenever I hear that phrase though!

-PatP

Boy that is such an opening...nah, better not...|||Boy that is such an opening...nah, better not...Allright! Where have you put the real Brett ?

-PatPsql

how to change Owner

i want to change the database owner to dbo.rightnow the owner is
test.i want to replace this owner with dbo.
i execute the sp_changeobjectowner 'tbluser' ,'dbo'
while i try to this i got the error
Server: Msg 15001, Level 16, State 1, Procedure
sp_changeobjectowner, Line 38
Object 'tblUser' does not exist or is not a valid object for this
operation.
i login as an 'sa' while trying to perform this operation.
Please let me know how do i change the owner.Try,
sp_changeobjectowner 'test.tbluser' ,'dbo'
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Mustafa" <Mustafa@.discussions.microsoft.com> wrote in message
news:616C728C-4CE0-4F9D-BC3A-947CE7A57388@.microsoft.com...
>i want to change the database owner to dbo.rightnow the owner is
> test.i want to replace this owner with dbo.
> i execute the sp_changeobjectowner 'tbluser' ,'dbo'
> while i try to this i got the error
> Server: Msg 15001, Level 16, State 1, Procedure
> sp_changeobjectowner, Line 38
> Object 'tblUser' does not exist or is not a valid object for this
> operation.
>
> i login as an 'sa' while trying to perform this operation.
> Please let me know how do i change the owner.

Wednesday, March 21, 2012

how to change default 'dbo' login info

Hi all,
sql server 2000.
I took over a database which has the system default
user: 'dbo' login as one of the consultants' name who left
the company already.
How can I change the login back to normal which should be
under 'sa'?
I tried to delete it and recreate 'dbo' for this database,
the system won't let me. I try to modify anything
on 'dbo', the system won't let me.
Help...
JJHi,
Does that user owns any object, if yes use the sp_changeobjectowner
procedure to change the owner to dbo. After that
use sp_changedbowner procedure to change the dbo to sa.
Thanks
Hari
MCDBA
"JJ Wang" <anonymous@.discussions.microsoft.com> wrote in message
news:103901c3dfc1$e3c226e0$a101280a@.phx.gbl...
quote:

> Hi all,
> sql server 2000.
> I took over a database which has the system default
> user: 'dbo' login as one of the consultants' name who left
> the company already.
> How can I change the login back to normal which should be
> under 'sa'?
> I tried to delete it and recreate 'dbo' for this database,
> the system won't let me. I try to modify anything
> on 'dbo', the system won't let me.
> Help...
> JJ
|||JJ
dbo is a user name, not a login name. Every db must have that user, so you
can't delete it. It is mapped to a LOGIN name in the master database and you
can change the mapping quite easily using the stored procedure
sp_changedbowner. There is no need to do anything with objects owned by
'dbo' user. Objects now owned by the user dbo will still be owned by dbo
after you change its mapping to point to the 'sa' login.
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"JJ Wang" <anonymous@.discussions.microsoft.com> wrote in message
news:103901c3dfc1$e3c226e0$a101280a@.phx.gbl...
quote:

> Hi all,
> sql server 2000.
> I took over a database which has the system default
> user: 'dbo' login as one of the consultants' name who left
> the company already.
> How can I change the login back to normal which should be
> under 'sa'?
> I tried to delete it and recreate 'dbo' for this database,
> the system won't let me. I try to modify anything
> on 'dbo', the system won't let me.
> Help...
> JJ

how to change default 'dbo' login info

Hi all,
sql server 2000.
I took over a database which has the system default
user: 'dbo' login as one of the consultants' name who left
the company already.
How can I change the login back to normal which should be
under 'sa'?
I tried to delete it and recreate 'dbo' for this database,
the system won't let me. I try to modify anything
on 'dbo', the system won't let me.
Help...
JJHi,
Does that user owns any object, if yes use the sp_changeobjectowner
procedure to change the owner to dbo. After that
use sp_changedbowner procedure to change the dbo to sa.
Thanks
Hari
MCDBA
"JJ Wang" <anonymous@.discussions.microsoft.com> wrote in message
news:103901c3dfc1$e3c226e0$a101280a@.phx.gbl...
> Hi all,
> sql server 2000.
> I took over a database which has the system default
> user: 'dbo' login as one of the consultants' name who left
> the company already.
> How can I change the login back to normal which should be
> under 'sa'?
> I tried to delete it and recreate 'dbo' for this database,
> the system won't let me. I try to modify anything
> on 'dbo', the system won't let me.
> Help...
> JJ|||JJ
dbo is a user name, not a login name. Every db must have that user, so you
can't delete it. It is mapped to a LOGIN name in the master database and you
can change the mapping quite easily using the stored procedure
sp_changedbowner. There is no need to do anything with objects owned by
'dbo' user. Objects now owned by the user dbo will still be owned by dbo
after you change its mapping to point to the 'sa' login.
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"JJ Wang" <anonymous@.discussions.microsoft.com> wrote in message
news:103901c3dfc1$e3c226e0$a101280a@.phx.gbl...
> Hi all,
> sql server 2000.
> I took over a database which has the system default
> user: 'dbo' login as one of the consultants' name who left
> the company already.
> How can I change the login back to normal which should be
> under 'sa'?
> I tried to delete it and recreate 'dbo' for this database,
> the system won't let me. I try to modify anything
> on 'dbo', the system won't let me.
> Help...
> JJ

how to change date format in a select statement

when i use this command in a aspx file

"SELECT DISTINCT Format$([dbo.classgiven.classdate], 'mm/yyyy') AS monthyear,{.......................

'Format$' is not a recognized function name.

so how do i change date from mm/dd/yyyy to mm/yyyy

Check out the CAST and CONVERT functions in SQL BOL. They have a listing of all the possible combinations of formatting you can do for datetime values.|||

Hi~

Try this:

SELECTRIGHT(CONVERT(VARCHAR(10), Column_Name, 103), 7)AS [MM/YYYY]from Table_Name
Hope it helps.

How to change database owner from SQL 6.5?

i'm performing sql server migration from 6.5 to server 2000,so i change the
database owner to dbo .i wanna change all the object owner to dbo
"acd" <acd@.msn.com> glsD:u$kU9FVfGHA.2456@.TK2MSFTNGP04.phx.gbl...
> i'm performing sql server migration from 6.5 to server 2000,so i change
> the database owner to dbo .
>|||DBO cannot be the database owner, as the database owner is a login name, and
dbo is a user name within the database. The login name which owns the
database ALWAYS maps to the user name dbo, so there is no way to change the
owners name to anything else, and no reason you would ever have to change
the name TO dbo.
For you second question, SQL 6.5 does not provide the option to change owner
names. It is possible to directly update the system tables to change object
ownership, but it is not supported and not recommended unless you have a LOT
of experience working with the system metadata. The support approach is to
drop the objects and then recreate them with the desired owner.
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"acd" <acd@.msn.com> wrote in message
news:em6jZKVfGHA.1264@.TK2MSFTNGP05.phx.gbl...
>i wanna change all the object owner to dbo
> "acd" <acd@.msn.com>
> glsD:u$kU9FVfGHA.2456@.TK2MSFTNGP04.phx.gbl...
>|||thanks for your reply...
i having a problem for testing database mirgration..
i facing the problem was..when i restore the the database to another sql
server 6.5 and performed database upgrade to 7.0. Since the object own by
different users..so some of the table can not move to 7.0
do u have any idea to help me that problem?
"Kalen Delaney" <replies@.public_newsgroups.com> glsD:%23Q%23iujVfGHA.4276@.TK2MSFTN
GP03.phx.gbl...
> DBO cannot be the database owner, as the database owner is a login name,
> and dbo is a user name within the database. The login name which owns the
> database ALWAYS maps to the user name dbo, so there is no way to change
> the owners name to anything else, and no reason you would ever have to
> change the name TO dbo.
> For you second question, SQL 6.5 does not provide the option to change
> owner names. It is possible to directly update the system tables to change
> object ownership, but it is not supported and not recommended unless you
> have a LOT of experience working with the system metadata. The support
> approach is to drop the objects and then recreate them with the desired
> owner.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.solidqualitylearning.com
>
> "acd" <acd@.msn.com> wrote in message
> news:em6jZKVfGHA.1264@.TK2MSFTNGP05.phx.gbl...
>

How to change database owner from SQL 6.5?

i'm performing sql server migration from 6.5 to server 2000,so i change the
database owner to dbo .i wanna change all the object owner to dbo
"acd" <acd@.msn.com> ¼¶¼g©ó¶l¥ó·s»D:u$kU9FVfGHA.2456@.TK2MSFTNGP04.phx.gbl...
> i'm performing sql server migration from 6.5 to server 2000,so i change
> the database owner to dbo .
>|||DBO cannot be the database owner, as the database owner is a login name, and
dbo is a user name within the database. The login name which owns the
database ALWAYS maps to the user name dbo, so there is no way to change the
owners name to anything else, and no reason you would ever have to change
the name TO dbo.
For you second question, SQL 6.5 does not provide the option to change owner
names. It is possible to directly update the system tables to change object
ownership, but it is not supported and not recommended unless you have a LOT
of experience working with the system metadata. The support approach is to
drop the objects and then recreate them with the desired owner.
--
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"acd" <acd@.msn.com> wrote in message
news:em6jZKVfGHA.1264@.TK2MSFTNGP05.phx.gbl...
>i wanna change all the object owner to dbo
> "acd" <acd@.msn.com>
> ¼¶¼g©ó¶l¥ó·s»D:u$kU9FVfGHA.2456@.TK2MSFTNGP04.phx.gbl...
>> i'm performing sql server migration from 6.5 to server 2000,so i change
>> the database owner to dbo .
>>
>|||thanks for your reply...
i having a problem for testing database mirgration..
i facing the problem was..when i restore the the database to another sql
server 6.5 and performed database upgrade to 7.0. Since the object own by
different users..so some of the table can not move to 7.0
do u have any idea to help me that problem?
"Kalen Delaney" <replies@.public_newsgroups.com> ¼¶¼g©ó¶l¥ó·s»D:%23Q%23iujVfGHA.4276@.TK2MSFTNGP03.phx.gbl...
> DBO cannot be the database owner, as the database owner is a login name,
> and dbo is a user name within the database. The login name which owns the
> database ALWAYS maps to the user name dbo, so there is no way to change
> the owners name to anything else, and no reason you would ever have to
> change the name TO dbo.
> For you second question, SQL 6.5 does not provide the option to change
> owner names. It is possible to directly update the system tables to change
> object ownership, but it is not supported and not recommended unless you
> have a LOT of experience working with the system metadata. The support
> approach is to drop the objects and then recreate them with the desired
> owner.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.solidqualitylearning.com
>
> "acd" <acd@.msn.com> wrote in message
> news:em6jZKVfGHA.1264@.TK2MSFTNGP05.phx.gbl...
>>i wanna change all the object owner to dbo
>> "acd" <acd@.msn.com> ¼¶¼g©ó¶l¥ó·s»D:u$kU9FVfGHA.2456@.TK2MSFTNGP04.phx.gbl...
>> i'm performing sql server migration from 6.5 to server 2000,so i change
>> the database owner to dbo .
>>
>>
>

How to change columns to rows

I have a need to change the columns in a table to rows with values
/****** Object: Table [dbo].[Test] Script Date: 5/23/2006 6:39:49 AM
******/
if not exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [Test] (
[UserID] [int] NULL ,
[NurseID] [int] NULL ,
[NurseID2] [int] NULL ,
[NurseID3] [int] NULL ,
[ReceptionID] [int] NULL ,
[OfficemanID] [int] NULL ,
[NurseTrainID] [int] NULL ,
[ResidentTrainID] [int] NULL ,
[ResidentTrainID2] [int] NULL ,
[ResidentTrainID3] [int] NULL
) ON [PRIMARY]
END
Insert into test
(UserID, NurseID,NurseID2, ReceptionID, OfficemanID)
values
(1,3,9,4,7)
Select * from Test would give
UserID NurseID, NurseID2
1 3 9
and I need to transform to using SQL2000
Description Users
UserID 1
NurseID 3
NurseID2 9
I may not need the description column
Thanks for the help
Stephen K. MiyasatoHi Stephen,
2005 allows using UNPIVOT clause. Not sure about 2000 though..
http://msdn2.microsoft.com/en-us/library/ms177410.aspx
"Stephen K. Miyasato" wrote:

> I have a need to change the columns in a table to rows with values
> /****** Object: Table [dbo].[Test] Script Date: 5/23/2006 6:39:49 AM
> ******/
> if not exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[Test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
> BEGIN
> CREATE TABLE [Test] (
> [UserID] [int] NULL ,
> [NurseID] [int] NULL ,
> [NurseID2] [int] NULL ,
> [NurseID3] [int] NULL ,
> [ReceptionID] [int] NULL ,
> [OfficemanID] [int] NULL ,
> [NurseTrainID] [int] NULL ,
> [ResidentTrainID] [int] NULL ,
> [ResidentTrainID2] [int] NULL ,
> [ResidentTrainID3] [int] NULL
> ) ON [PRIMARY]
> END
> Insert into test
> (UserID, NurseID,NurseID2, ReceptionID, OfficemanID)
> values
> (1,3,9,4,7)
> Select * from Test would give
> UserID NurseID, NurseID2
> 1 3 9
> and I need to transform to using SQL2000
> Description Users
> UserID 1
> NurseID 3
> NurseID2 9
> I may not need the description column
> Thanks for the help
> Stephen K. Miyasato
>
>|||If you were using SQL Server 2005, you could use an UNPIVOT statement.
In this case, I think you'll just have to use a series of UNION ALL
statements to transform the data, as in:
select
'UserID' as Description,
UserID as Users
from test
UNION ALL
select
'NurseID' as Description,
NurseID as Users
from test
UNION ALL
select
'NurseID2' as Description,
NurseID2 as Users
from test|||If you were using SQL Server 2005, you could use an UNPIVOT statement.
In this case, I think you'll just have to use a series of UNION ALL
statements to transform the data, as in:
select
'UserID' as Description,
UserID as Users
from test
UNION ALL
select
'NurseID' as Description,
NurseID as Users
from test
UNION ALL
select
'NurseID2' as Description,
NurseID2 as Users
from test|||For SS2000, you can refer to the following.
- How to rotate a table in SQL Server
http://support.microsoft.com/defaul...kb;en-us;175574
Martin C K Poon
Senior Analyst Programmer
====================================
"Stephen K. Miyasato" <miyasat@.flex.com> bl
news:%23d67IiofGHA.4864@.TK2MSFTNGP05.phx.gbl g...
> I have a need to change the columns in a table to rows with values
> /****** Object: Table [dbo].[Test] Script Date: 5/23/2006 6:39:49 AM
> ******/
> if not exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[Test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
> BEGIN
> CREATE TABLE [Test] (
> [UserID] [int] NULL ,
> [NurseID] [int] NULL ,
> [NurseID2] [int] NULL ,
> [NurseID3] [int] NULL ,
> [ReceptionID] [int] NULL ,
> [OfficemanID] [int] NULL ,
> [NurseTrainID] [int] NULL ,
> [ResidentTrainID] [int] NULL ,
> [ResidentTrainID2] [int] NULL ,
> [ResidentTrainID3] [int] NULL
> ) ON [PRIMARY]
> END
> Insert into test
> (UserID, NurseID,NurseID2, ReceptionID, OfficemanID)
> values
> (1,3,9,4,7)
> Select * from Test would give
> UserID NurseID, NurseID2
> 1 3 9
> and I need to transform to using SQL2000
> Description Users
> UserID 1
> NurseID 3
> NurseID2 9
> I may not need the description column
> Thanks for the help
> Stephen K. Miyasato
>|||Thanks very much,
That is what I was looking for.
Stephen
"dterrie" <dterrie@.axiomadvisors.net> wrote in message
news:1148404941.573763.96380@.i39g2000cwa.googlegroups.com...
> If you were using SQL Server 2005, you could use an UNPIVOT statement.
> In this case, I think you'll just have to use a series of UNION ALL
> statements to transform the data, as in:
> select
> 'UserID' as Description,
> UserID as Users
> from test
> UNION ALL
> select
> 'NurseID' as Description,
> NurseID as Users
> from test
> UNION ALL
> select
> 'NurseID2' as Description,
> NurseID2 as Users
> from test
>

Monday, March 19, 2012

How to CASE a SmallInt to a Varchar value

Why does this syntax work for bit but not for smallint ?
-- This works OK - Setting = BIT
CASE (dbo.tblAssessment.Setting)
WHEN 1 THEN 'Internal'
WHEN 0 THEN 'External'
END AS Setting,
-- This fails - error converting value 'N/A' to column of datatype smallint
-- Credit = SMALLINT
CASE (dbo.tblAssessment.Credit)
WHEN 101 THEN 'N/A'
ELSE dbo.tblAssessment.Credit
END AS Credit,
Thanks.Hi
It is expecting to return a smallint as one of the ELSE's in a smallint.
CASE (dbo.tblAssessment.Credit)
WHEN 101 THEN CONVERT(CHAR(10), 'N/A' )
ELSE CONVERT(CHAR(10), dbo.tblAssessment.Credit)
END AS Credit
Regards
Mike
"hals_left" wrote:

> Why does this syntax work for bit but not for smallint ?
>
> -- This works OK - Setting = BIT
> CASE (dbo.tblAssessment.Setting)
> WHEN 1 THEN 'Internal'
> WHEN 0 THEN 'External'
> END AS Setting,
> -- This fails - error converting value 'N/A' to column of datatype smallin
t
> -- Credit = SMALLINT
> CASE (dbo.tblAssessment.Credit)
> WHEN 101 THEN 'N/A'
> ELSE dbo.tblAssessment.Credit
> END AS Credit,
> Thanks.
>

Monday, March 12, 2012

How to call talbe/SP from Linked server with out database and user

Dear Friends,
Usually we call tabal and SP like given below.
select * from [linkedserver].[database].[dbo].[TableName]
EXEC [linkedserver].[database].[dbo].usp_storedprocedure
but I like to all with out database and username.
I tryed like below
select * from [linkedserver]...[TableName]
OR
select * from [linkedserver]..[user].[TableName]
It's gives error
Server: Msg 7313, Level 16, State 1, Line 1
Invalid schema or catalog specified for provider 'MSDASQL'.
OLE DB error trace [Non-interface error: Invalid schema or catalog
specified for the provider.].
Please help me to achive this.
Thasks and regards,
Rajesh
On Wed, 14 Sep 2005 07:57:08 -0700, Rajesha wrote:

>Dear Friends,
>Usually we call tabal and SP like given below.
> select * from [linkedserver].[database].[dbo].[TableName]
> EXEC [linkedserver].[database].[dbo].usp_storedprocedure
>but I like to all with out database and username.
>I tryed like below
>select * from [linkedserver]...[TableName]
>OR
>select * from [linkedserver]..[user].[TableName]
>It's gives error
>Server: Msg 7313, Level 16, State 1, Line 1
>Invalid schema or catalog specified for provider 'MSDASQL'.
>OLE DB error trace [Non-interface error: Invalid schema or catalog
>specified for the provider.].
>Please help me to achive this.
>Thasks and regards,
>Rajesh
Hi Rajesh,
You can't leave out the databasename. A linked server might hold more
than one database, so you have to specify that part.
I believe that you can leave out the owner, but I'm not sure, and I
can't test that right now. However, it is recommended that you always
include the owner. This helps SQL Server find the object more quickly,
and it helps reduce the number of recompiles.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

Wednesday, March 7, 2012

How to Call a function using OLE DB Command Transformation

Hello

i am trying to call a function from the SQL server using Ole DB command Transformation using [dbo].[ConvertToDate] ?,?,?,?

there are no errors while executing this transformation

but this function returns a value

Now i need to capture this value how do i do that using the OLE DB command Transformation or any other transformation

Thanks

Hello Please can somebody answer this question|||

I don't believe that the OLE DB Command transform can capture the return value from a scalar function. You can work around this by calling the function inside a stored procedure, and returning the function's return as an output parameter from the procedure.

There is an article that demonstrates this technique (output parameter handling, not function wrapping) here: http://wiki.sqlis.com/default.aspx/SQLISWiki/OLEDBCommandTransformationAndIdentityColumns.html?diff=y

How to Call a function using OLE DB Command Tranformation

Hello

i am trying to call a function from the SQL server using Ole DB command Transformation using [dbo].[ConvertToDate] ?,?,?,?

there are no errors while executing this transformation

but this function returns a value

Now i need to capture this value how do i do that using the OLE DB command Transformation or any other transformation

Thanks

Hello Please can somebody answer this question|||

I don't believe that the OLE DB Command transform can capture the return value from a scalar function. You can work around this by calling the function inside a stored procedure, and returning the function's return as an output parameter from the procedure.

There is an article that demonstrates this technique (output parameter handling, not function wrapping) here: http://wiki.sqlis.com/default.aspx/SQLISWiki/OLEDBCommandTransformationAndIdentityColumns.html?diff=y