Swapping the first and last characters in a column
Hi,
Fairly new to T-SQL and i want to swap the first and last characters in a column.
Thanks
Umar Javed
Likewise i have also tried your suggestion and i still seem to be getting errors:
IF (@TYPE = 'SCRAMBLE')
BEGIN
DECLARE @SQLCOMMAND VARCHAR(2000)
SET @SQLCOMMAND = 'UPDATE ' + @TABLENAME + ' SET ' + @VALUE +
STUFF(STUFF(@VALUE,1,1,RIGHT(@VALUE,1)),LEN(@VALUE),1,LEFT(@VALUE,1))
EXECUTE(@SQLCOMMAND)
END
Umar Javed
Please post the errors.
EDIT: Actually looking at your code this will bring errors:
IF (@TYPE = 'SCRAMBLE')
BEGIN
DECLARE @SQLCOMMAND VARCHAR(2000)
SET @SQLCOMMAND = 'UPDATE ' + @TABLENAME + ' SET ' + @VALUE + ' = STUFF(STUFF('+@VALUE+',1,1,RIGHT('+@VALUE+',1)),LEN('+@VALUE+'),1,LEFT('+@VALUE+',1))'
PRINT @SQLCOMMAND
EXECUTE(@SQLCOMMAND)
END
I've also added a print command so it will show you what the code looks like upon concatenation. It's much easier to debug this way.
Similar Messages
-
How to compare the first and last characters of strings?
lets say we have a name column with values;
c1
Antu Anamentu
Steven Smith
Since A=A and U=U for the first value we need a TRUE and FALSE for the second value SQL. Is this possible to do with REGEXP functions on 10gR2.
Thank you.Hi Frank,
Just minor correction: REGEXP_LIKE (Name1, '^(.).*(.) \1.*\2$') ;
Explanation: ^(.) =>^ specifies the next char is first char
. dot specifies single character
() defines group which can be backrferenced
.* => Any number of characters as we want only first and last character
(.) => (.)space The space signifies that we want to remember last char of first word or char before space
\1 => It recalls first group which we saved for backreference using (.)
.* => Any number of chars
\2 => It recalls first group which we saved for backreference using (.)
$ => It specifies the char before this is last charHope it clarifies :)
SQL> WITH t AS
SELECT 'Antu Anamentu' Name1 FROM DUAL UNION ALL
SELECT 'Steven Smith' Name1 FROM DUAL
SELECT Name1
FROM t
WHERE REGEXP_LIKE (Name1, '^(.).*(.) \1.*\2$') ;
NAME1
Antu Anamentu -
How can I display the first and last name using a paramater as employee ID?
Hi SAP,
I have a parameter that is called {? Employee ID}. What I want to do is display the first and last name based on the employee ID value entered in {? Employee ID} in the page header of the report. Right now, when I put the following formula in the page header only some pages get the right result while other pages dont....
if table.employeeid = {? Employee ID} then
table.firstname" "table.lastname
It appears as though if the first record in the details section on the beginning of each page happens to be the employee under {? Employee ID} then it prints it correctly, if it isn't I get a null value in the page header.
Anyone have any ideas?
ZHi Try this,
Whileprintingrecords;
if ={?EmpID} then
Also check the option "Default values for null" in the formula editor.
Regards,
Vinay -
How to show the First and Last name of the user instead of user name
Gurus,
We have the full email id of the user as the portal user name. Right now we are using the "Item Attributes - Current User" to show the user name. We don't want to show this anymore. We would like to show the First and Last name of the user on the Portal page. How can i do this. Please post a reply if you have some idea about it.
Thanks
Raj
---------I believe this is possible using the security APIs. See http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/PLSQL/DOC/PLDOC_9026/INDEX.HTML and look for person_info (Returns user information, given a user name)
under wwsec_api
Suggest posting any follow-up questions to the Security forum - http://forums.oracle.com/forums/forum.jsp?forum=6 -
I need to build a linear list of the string positions of the
first and last character of each word in a string. For example if I
have the string myPet = “DOG CAT FISH” then myList =
[[1,3],[5,7],[9,12]]
myPet.word[x] will let me access the individual words but
I’m not sure how to get the char position of the beginning
and end of each. Please help, it’s Friday and my brain has
left for the weekend.Touche, Sean.
"Sean Wilson" <[email protected]> wrote in
message
news:fqa8ap$bga$[email protected]..
> Hi Craig,
>
> Your's fails if any word is repeated. Try it with "DOG
CAT FISH DOG"
>
> This one seems to work, although there are probably more
efficient ways to
> go about it. A regular expression and the PRegEx xtra
would certainly be
> quicker, especially as the string gets longer
>
> on mGetWordBoundaries aString
> -- basic error check
> if stringP(aString) = 0 then return []
> if length(aString) = 0 then return []
>
> lWhitespace = [SPACE, TAB, RETURN, numToChar(10)]
> tStart = 1
> tChar = aString.char[tStart]
> repeat while lWhitespace.getPos(tChar)
> tStart = tStart + 1
> tChar = aString.char[tStart]
> end repeat
>
> lPositions = []
> repeat with w = 1 to aString.word.count
> tEnd = tStart + aString.word[w].char.count - 1
> lPositions.append([tStart, tEnd])
> tStart = tEnd + 1
> tChar = aString.char[tStart]
> repeat while lWhitespace.getPos(tChar)
> tStart = tStart + 1
> tChar = aString.char[tStart]
> end repeat
> end repeat
> return lPositions
> end -
I've bought the season 1 of "The Wire" (7episodes), when I synchronize with my PC, it only charge the first and last episodes and not the 5 episodes in between ??
Hello spinozette,
I am sure you are eager to download and watch Season 1 of The Wire. I found a couple of resources that might help with downloading this purchase.
First, I recommend checking to see if the download was interrupted. You can use the steps in this article:
iTunes: How to resume interrupted iTunes Store downloads
http://support.apple.com/kb/HT1725
If the episodes do not download after following the steps in that article, I recommend trying to download the episodes from the list of past purchases. You can find the steps to do this in the section titled "Apps, Books, Music, Movies, or TV shows on a computer" in the following article:
Downloading past purchases from the App Store, iBookstore, and iTunes Store
http://support.apple.com/kb/HT2519
If you are still not able to download the rest of the season, I recommend reporting this issue to the iTunes Store:
How to report an issue with your iTunes Store, App Store, Mac App Store, or iBooks Store purchase
http://support.apple.com/kb/HT1933
Thank you for using Apple Support Communities.
Best,
Sheila M. -
SQL Selecting the first and last entries for each day
Hello SQL experts,
I hope you can help with this.. I have a table (could have 1M or more rows in it) see structure below. I am looking to get the first and last date/times for each employee for each day. I also need the location GUID for the first read.
EmployeeGUID (uniqueidentifier datatype)
LocationGUID (uniqueidentifier datatype)
DateTime (DateTime datatype)
12345678-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/12/2014 07:00:01
12345678-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/12/2014 10:40:05
12345678-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/12/2014 17:04:02
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 08:00:00
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 14:00:03
44422222-0000-0000-0000-000000000000
33333333-0000-0000-0000-000000000000
04/15/2014 07:49:00
44422222-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/15/2014 09:00:01
This would be the ideal output (I can do without the TotalTimeInHours):
EmployeeGUID (uniqueidentifier datatype)
LocationGUID (uniqueidentifier datatype)
FirstRead (DateTime datatype)
LastRead (DateTime datatype)
TotalTimeInHours
12345678-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/12/2014 07:00:01
04/12/2014 17:04:02
Total in hours between the first and last read.
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 08:00:00
04/14/2014 14:00:03
44422222-0000-0000-0000-000000000000
33333333-0000-0000-0000-000000000000
04/15/2014 07:49:00
04/15/2014 09:00:01
I would post what I have tried so far but I have been trying many different types of queries over the last few days. In short I need the employees first and last reads for each date. They could have many entries per date or just 1. I am certain that this
is a trivial thing for a SQL expert but not trivial for me :).
Thank you in advance!Thank you!
This is almost what I need. The LocationGUID has to be included in the output. When I include it, I have to put it in the Group By clause. When I do that the reads are based on the LocationGUID (see below).
** I added a few more data entries and included the LocationGUID in the output.
***** SQL ***********
CREATE TABLE test( EmployeeGUID uniqueidentifier, LocationGUID uniqueidentifier, DateTimeCol DateTime )Insert into test values
('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/12/2014 07:00:01')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 10:40:05')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 17:04:02')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 19:00:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 08:00:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 14:04:03')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 07:49:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 09:00:01')
,('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/13/2014 10:40:05')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 17:04:02')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 19:00:00')
;with mycte as (
SELECT *, row_number() OVER(partition by EmployeeGUID, Cast(DateTimeCol as date) Order by DateTimeCol) rnASC,
row_number() OVER (partition by EmployeeGUID, Cast(DateTimeCol as date) Order by DateTimeCol DESC) rnDESC
FROM test)
Select EmployeeGUID ,Cast(DateTimeCol as date) dt,LocationGUID,
Max(Case when rnASC=1 Then DateTimeCol End) minDateTimeCol
,Max(Case when rnDESC=1 Then DateTimeCol End ) maxDateTimeCol
,Datediff(minute, Max(Case when rnASC=1 Then DateTimeCol End) ,Max(Case when rnDESC=1 Then DateTimeCol End ) )/60.0 TotalTimeInHours
from mycte
Group by EmployeeGUID, LocationGUID,Cast(DateTimeCol as date)
Order by dt,EmployeeGUID
drop TABLE test
**** OUTPUT **********
EmployeeGUID
dt
LocationGUID
minDateTimeCol
maxDateTimeCol
TotalTimeInHours
12345678-0000-0000-0000-000000000000
2014-04-12
11111111-0000-0000-0000-000000000000
2014-04-12 07:00:01.000
NULL
NULL
12345678-0000-0000-0000-000000000000
2014-04-12
22222222-0000-0000-0000-000000000000
NULL
2014-04-12 19:00:00.000
NULL
12345678-0000-0000-0000-000000000000
2014-04-13
11111111-0000-0000-0000-000000000000
2014-04-13 10:40:05.000
NULL
NULL
12345678-0000-0000-0000-000000000000
2014-04-13
22222222-0000-0000-0000-000000000000
NULL
2014-04-13 19:00:00.000
NULL
44422222-0000-0000-0000-000000000000
2014-04-14
22222222-0000-0000-0000-000000000000
2014-04-14 08:00:00.000
2014-04-14 14:04:03.000
6.066666 -
How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, what do I select if I mark the first and last email to delete everything in between? Thanks.
I have this same issue. I have over 100 email addresses that I need to add to a group. The issue is not making the group, it's getting the email addresses from Mail to Contacts.
Dragging the email addresses does nothing. You can copy the addresses, but there's nowhere to put them. You can make a VCF for an email address, but then you have to find all of them to add them to the group. How do you automate this?!
I'm astounded that there's so little support for such a common issue for which people have been asking for years. -
How to get the first and last record
Hai All
I have table called T1 and there are more than 8 lakhs records and i have a column called Timestamp so i need to get the first record value and time stampvalue and last record and time stamp value so that i can conclude that For Example
form 13 june to 15 june data are here
Kind Regards
SrikkanthMSomething like this can also indicate the first and last rows as you query...
SQL> select empno, ename, hiredate
2 ,case row_number() over (order by hiredate)
3 when 1 then 'First Row'
4 when count(*) over () then 'Last Row'
5 end as flag
6 from emp;
EMPNO ENAME HIREDATE FLAG
7369 SMITH 17/12/1980 00:00:00 First Row
7499 ALLEN 20/02/1981 00:00:00
7521 WARD 22/02/1981 00:00:00
7566 JONES 02/04/1981 00:00:00
7698 BLAKE 01/05/1981 00:00:00
7782 CLARK 09/06/1981 00:00:00
7844 TURNER 08/09/1981 00:00:00
7654 MARTIN 28/09/1981 00:00:00
7839 KING 17/11/1981 00:00:00
7900 JAMES 03/12/1981 00:00:00
7902 FORD 03/12/1981 00:00:00
7934 MILLER 23/01/1982 00:00:00
7788 SCOTT 19/04/1987 00:00:00
7876 ADAMS 23/05/1987 00:00:00 Last Row
14 rows selected.
SQL> -
When was the first and last login of a db user
Hi @ all,
I'm trying to find out the first and the last login of a special db user at an Oracle 10g (10.2.0.1.0) Instance.
How can I do that?
Thanks and best regards,
DavidWhat Nicholas said is true, but depending what you are looking for, you may also search/review audit files created by everytime a sysdba or sysoper session was created by looking in your audit directory.
From within sqlplus, "show parameter audit"
Then, go to that directory and you will see hundreds/thousands of audit files for each time a sysdba or sysoper session was started.
Within those logs are entries such as:
Tue Mar 12 16:00:00 2013 -04:00
LENGTH : '155'
ACTION :[7] 'CONNECT'
DATABASE USER:[1] '/'
PRIVILEGE :[6] 'SYSDBA' <=========== sysdba or sysoper (I believe this is all that is captured.)
CLIENT USER:[6] 'oracle' <=========== shows the OS user that connected to the database
CLIENT TERMINAL:[0] ''
STATUS:[1] '0'
DBID:[10] '1321231341' -
Find the first and last day of week giving a certain date
Hi,
i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?
Many thanks in advance,
Nuno Almeidanfalmeida wrote:
i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?First step is being sure that you know what a 'week' is.
For example does it really start on monday? And will it always start on monday?
And what day does the 'week' end on for 2010-12-29? In some businesses it will end on 2010-12-31 (friday) -
How we claculate the first and last date of the month
hi,
I have a requirement, if i have the any date of a month like today date 02/13/2008. So i want the first date of this month and the last date of this month.
Is there any FM for this..or if you have nay prorgam pls send to me.
thanks.Hi Vipin,
Try
HR_JP_MONTH_BEGIN_END_DATE FM will return both first day and last day
LAST_DAY_OF_MONTHS for getting last day of month.
Reward if helpful.
Regards,
Mandeep -
What does the First and Last Unbrick date mean?
I got an iphone 4 from someone and it's supposed to be on Telus but isn't working with their sims. I got it checked on iphoneosunlock.com and they confirmed its with telus but also said was:
First Unbrick Date: 23/08/12
Last Unbrick Date 30/08/13
The last unbrick date is tomorrow so does anyone know what this means or what will happen?Apple refers to activating a device as "unbricking." Your "last unbrick date" is the last date the device was activated with a carrier according to Apple's systems. As this information is always sent to Apple from all carriers that want to activate devices with a carrier profile (device settings specific to each carrier). If you activate a device with multiple carriers through its life (take it from T-Mobile to Aio Wireless for example), it will have multiple unbrick dates in the device history maintained with Apple.
-
Over the period of a day or three the tab bar stops responding to attempts to scroll the tab bar. I can still advance through the tabs with ctrl-tab and shift-ctrl-tab but the tab scroll arrows either don't work at all or work erratically.
A "solution" that requires restarting the program is not a solution at all. This is a bug in Firefox - once you have enough tabs open, tab scrolling becomes unresponsive, and tabs at the far right and left cannot be tabbed to at all. It is also not a solution to open less tabs; if I want 50 tabs open, and work best that way, then FF should permit that. It does not do so now.
Thanks. -
Problems with envelope-printing in Address Book: First and Last names
New entries I make in Address Book are printing incorrectly, with Last name then First name. Most of my older entries print correctly as First name then Last name (though oddly I have a small batch of entries I imported ages ago which have always exhibited the same transposition problem).
I have prefs set to display entries by Last name. Problem entries WILL print correctly if I change this to 'display by First name'. (older entries print correctly regardless of 'display by..' pref).
I'm having the same problem if I create a new account, which made me suspect the app was corrupted, but not helped by deleting app and re-installing from Tiger DVD then running combo updater.Thank you for the suggestion.
However, it doesn't make sense for the LIST display-order to swap the first-and-last names on an ENVELOPE. Secondly, most of my entries DO print correctly: it's only NEW entries that transpose the first and last names.
Maybe you are looking for
-
MAC and iTunes is not recognizing my 5th generation iPod touch with smaller charger plug. What can I do to fix?
-
Can't get PersistenceUnit to work
Hi all, I am setting up the Netbeans 6.0 IDE with JSF1.2, Tomcat 6.0 and Hibernate through JPA. I am newbie on JavaEE though not on JavaSE and Netbeans. However I am having painfully difficulties in making some tests and trials, to gain deeper knowle
-
How to add data in the saved spreadshee​t file
Hi all, I am having trouble in adding data onto an already saved spreadsheet file. I don't want to overwrite the old file but modify it, such that the new data is stored below the old data. Or As I am saving the data in a 2-D array in the VI, where t
-
Outllook clients sending partial messages / truncated email body
I am stumped on this one and could use a little help. Several clients are experiencing partially truncated emails both sent and received. It is happening on Outlook 2003 and 2010. The Sent Items folder also shows the truncated email. For instance, le
-
Library window blanked out after V4
"Library" window (previously "Organize favorites") is blanked out, although at least a folder "Imported from IE" is present in the Favorites menu. Also, in the "File" menu only "import" option is presented (and not import/export). This happened after