Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
bhushanhegde
Starting Member
14 Posts |
Posted - 2008-11-28 : 01:10:55
|
| Hi,I need one more help in converting my oracle query into SQL Server 2005.Query is as follows:SELECT g.groupid GroupId,lpad(' ',5*(level-1),'-') || groupname groupname, g.parent_groupid,g.root_groupid FROM fm_profilegroup gWHERE Active_Flag='Y' START WITH parent_groupid=0 CONNECT BY PRIOR groupid=parent_groupid ;ORDER BY root_groupid,groupid;can anyone solve this?Regardsbhushan |
|
|
darkdusky
Aged Yak Warrior
591 Posts |
Posted - 2008-11-28 : 09:24:00
|
| The link below creates Rpad and Lpad functions in SQL Server.http://dbasqlserver.blogspot.com/2006/09/sql-server-t-sql-lpad-rpad-functions.htmlHere are the functions:IF EXISTS (SELECT *FROM dbo.sysobjectsWHERE id = object_id(N'[dbo].[fnPadRight]')AND xtype IN (N'FN', N'IF', N'TF'))DROP FUNCTION [dbo].[fnPadRight]GOSET QUOTED_IDENTIFIER ONGOSET ANSI_NULLS ONGOCREATE FUNCTION fnPadRight(@PadChar char(1),@PadToLen int,@BaseString varchar(100))RETURNS varchar(1000)AS/* ****************************************************Description:Pads @BaseString to an exact length (@PadToLen) using thespecified character (@PadChar). Base string will not betrimmed. Implicit type conversion should allow caller topass a numeric T-SQL value for @BaseString.Unfortunately T-SQL string variables must be declared with anexplicit width, so I chose 100 for the base and 1000 for thereturn. Feel free to adjust data types to suit your needs.Keep in mind that if you don't assign an explicit width tovarchar it is the same as declaring varchar(1).Revision History:Date Name Description---- ---- -----------**************************************************** */BEGINDECLARE @Padded varchar(1000)DECLARE @BaseLen intSET @BaseLen = LEN(@BaseString)IF @BaseLen >= @PadToLenBEGINSET @Padded = @BaseStringENDELSEBEGINSET @Padded = @BaseString + REPLICATE(@PadChar, @PadToLen - @BaseLen)ENDRETURN @PaddedENDGOSET QUOTED_IDENTIFIER OFFGOSET ANSI_NULLS ONGOIF EXISTS (SELECT *FROM dbo.sysobjectsWHERE id = object_id(N'[dbo].[fnPadRight]')AND xtype IN (N'FN', N'IF', N'TF'))DROP FUNCTION [dbo].[fnPadRight]GOSET QUOTED_IDENTIFIER ONGOSET ANSI_NULLS ONGOCREATE FUNCTION fnPadRight(@PadChar char(1),@PadToLen int,@BaseString varchar(100))RETURNS varchar(1000)AS/* ****************************************************Description:Pads @BaseString to an exact length (@PadToLen) using thespecified character (@PadChar). Base string will not betrimmed. Implicit type conversion should allow caller topass a numeric T-SQL value for @BaseString.Unfortunately T-SQL string variables must be declared with anexplicit width, so I chose 100 for the base and 1000 for thereturn. Feel free to adjust data types to suit your needs.Keep in mind that if you don't assign an explicit width tovarchar it is the same as declaring varchar(1).Revision History:Date Name Description---- ---- -----------**************************************************** */BEGINDECLARE @Padded varchar(1000)DECLARE @BaseLen intSET @BaseLen = LEN(@BaseString)IF @BaseLen >= @PadToLenBEGINSET @Padded = @BaseStringENDELSEBEGINSET @Padded = @BaseString + REPLICATE(@PadChar, @PadToLen - @BaseLen)ENDRETURN @PaddedENDGOSET QUOTED_IDENTIFIER OFFGOSET ANSI_NULLS ONGO |
 |
|
|
|
|
|
|
|