Question

SQL and trying for a solution. Case: Our System runs different Business process and outputs process result set into a new table called "Export_PROCESSSID". The ProcessID is GUID (XXX-XFG-EDRT ) but when the system creates the table it uses the ProcessID but rename it to (Export_XXX_XFG_EDRT). Hyphens are replaced with underscores and prefixed with "Export_".

Sofar: First, I run a select statement to find the latest Process_ID in the table. Now I need to rename this GUID from this format "04ad20f5-3be6-481a-b341-d32f7702179f" to this "Export_04ad20f5_3be6_481a_b341_d32f7702179f".

Any ideas doing this t-sql with replace function or other methods? I am stuck here, any help will be appreciated. Many thanks.

Was it helpful?

Solution

I'm not sure what your context is, but this will transform XXX-XFG-EDRT into Export_XXX_XFG_EDRT:

'Export_' + REPLACE(ProcessID, '-', '_')

OTHER TIPS

For neatness, convert your GUID into a varchar first, then run REPLACE on it:

DECLARE @guid uniqueidentifier
SET @guid = newid()
SELECT 'Export_' + REPLACE(CONVERT(varchar(50), @guid), '-', '_')

Returns (at least, the last time I ran it):

Export_8D997451_F7B6_4EC5_9CFC_478B7084811A
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top