| Author |
Topic |
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-03-19 : 14:32:45
|
| create a function to reverese a string pass it abcd and it returns dcba you can't use the built in reverese function... |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-19 : 14:40:45
|
| We do not do homework here.In real life scenarios, there is absolutely no law against using REVERSE function.If your professor can't make better exams, tell him he's a twit.Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-19 : 15:03:37
|
| DECLARE @String VARCHAR(20)SELECT @String = 'abcd'DECLARE @Len INTSELECT @Len = DATALENGTH(@String)DECLARE @Result VARCHAR(20)SELECT @Result = ''WHILE @Len > 0 BEGIN SET @Result = @Result + SUBSTRING(@String, @Len, 1) SET @Len = @Len - 1ENDPeter LarssonHelsingborg, Sweden |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-03-19 : 15:05:47
|
| so he asked nicly and you did his homework for him?nice going..._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-19 : 15:08:29
|
| I figured out he would never even know or acknowledge what BOL is...Peter LarssonHelsingborg, Sweden |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-03-19 : 15:34:21
|
| I tested your syntax embedding in the functions and it works great. I might have further questions on it.CREATE function reverseString (@inString varchar(200) )returns varchar(200)asBEGINDECLARE @String VARCHAR(20)SELECT @String = 'abcd'DECLARE @Len INTSELECT @Len = DATALENGTH(@String)DECLARE @Result VARCHAR(20)SELECT @Result = ''WHILE @Len > 0 BEGINSET @Result = @Result + SUBSTRING(@String, @Len, 1)SET @Len = @Len - 1endreturn @resultENDselect dbo.reverseString('abcd') |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-03-19 : 15:44:25
|
| DECLARE @String VARCHAR(20)SELECT @String = 'abcd' -- how can i make the user choose their own string to input from the function call.So, far you have been very grateful. |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-03-19 : 16:15:33
|
http://msdn2.microsoft.com/en-us/library/ms186755.aspx www.elsasoft.org |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-19 : 16:21:28
|
| CREATE function dbo.reverseString (@inString varchar(200) )returns varchar(200)asBEGINDECLARE @Len INTSELECT @Len = DATALENGTH(@inString)DECLARE @Result VARCHAR(200)SELECT @Result = ''WHILE @Len > 0 BEGINSET @Result = @Result + SUBSTRING(@inString, @Len, 1)SET @Len = @Len - 1endreturn @resultENDselect dbo.reverseString('abcd')Peter LarssonHelsingborg, Sweden |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-03-19 : 16:56:56
|
| This has been very helpful. I would like to go in detail, discussion of each syntax. I mean if you could comment out what's going on would be very helpful.I'm using, the book, Beginning Sql, by paul wilton, john Colby and some of the stuffs you specified aren't in the book. http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764577328.html I'm using this book. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-19 : 19:14:56
|
Refer to this book. All the stuff used in the function is cover in this book. Best of all, it is F R E E KH |
 |
|
|
|