Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

LastName UPPER(LastName) LOWER(LastName) Hawthorn HAWTHORN hawthorn Gee GEE gee Doors DOORS doors Dales DALES dales Botts BOTTS botts Now that you know how to change a string’s case, the next section looks at how to turn a string backward. The REVERSE() Function The REVERSE() function reverses the order of the characters in a string. For example, ABC becomes CBA. It takes just one argument, the string to be reversed. MS Access calls its REVERSE() function the StrReverse() function, and it works the same. IBM DB2 doesn’t support the REVERSE() function. The following SQL returns LastName and LastName reversed: SELECT LastName, Reverse(LastName) FROM MemberDetails; The results of the query appear in the following table: LastName REVERSE(LastName) Smith htimS Simons snomiS Night thgiN Jones senoJ Jones senoJ Johnson nosnhoJ Jackson noskcaJ Hills slliH Hawthorn nrohtwaH Gee eeG Doors srooD Dales selaD Botts sttoB Manipulating Data 171

LastName UPPER(LastName) LOWER(LastName)<br />

Hawthorn HAWTHORN hawthorn<br />

Gee GEE gee<br />

Doors DOORS doors<br />

Dales DALES dales<br />

Botts BOTTS botts<br />

Now that you know how to change a string’s case, the next section looks at how to turn a string backward.<br />

The REVERSE() Function<br />

The REVERSE() function reverses the order of the characters in a string. For example, ABC becomes<br />

CBA. It takes just one argument, the string to be reversed. MS Access calls its REVERSE() function the<br />

StrReverse() function, and it works the same. IBM DB2 doesn’t support the REVERSE() function.<br />

The following <strong>SQL</strong> returns LastName and LastName reversed:<br />

SELECT LastName, Reverse(LastName)<br />

FROM MemberDetails;<br />

The results of the query appear in the following table:<br />

LastName REVERSE(LastName)<br />

Smith htimS<br />

Simons snomiS<br />

Night thgiN<br />

Jones senoJ<br />

Jones senoJ<br />

Johnson nosnhoJ<br />

Jackson noskcaJ<br />

Hills slliH<br />

Hawthorn nrohtwaH<br />

Gee eeG<br />

Doors srooD<br />

Dales selaD<br />

Botts sttoB<br />

Manipulating Data<br />

171

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!