Author |
Topic |
deekshan
Starting Member
5 Posts |
Posted - 2008-09-22 : 03:24:30
|
my cell value is "mcd\categories\aa\finance.htm."the first part(mcd\categories) are same for column...Remaining values differs for other cells in the column..I want to display the value after the categories but before the next slash..For example: my output for this cell is "aa"Pls help me to write the query to display the value.Thanks in advance |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-22 : 03:30:13
|
[code]DECLARE @Sample TABLE ( Col1 VARCHAR(200) )INSERT @SampleSELECT 'mcd\categories\aa\finance.htm'SELECT Col1, REVERSE(PARSENAME(REPLACE(REVERSE(SUBSTRING(Col1, 16, 200)), '\', '.'), 1))FROM @Sample[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-22 : 03:57:30
|
orSELECT Col1, PARSENAME(REPLACE(REPLACE(Col1,'.', ''),'\','.'), 2)FROM @Sample MadhivananFailing to plan is Planning to fail |
 |
|
deekshan
Starting Member
5 Posts |
Posted - 2008-09-22 : 05:07:54
|
Thanks for your reply.But its returning NULLEg:My column is \MCD\Categories\InfoKiosk\Communication\1.htm\MCD\Categories\InfoKiosk\Communication\2.htm\MCD\Categories\Corporate Guidelines\Booking Form for Penthouse at JTC Summit.doc\MCD\Categories\Corporate Identity\guidelines_for_use_of_new_jtc_lo.htmMy output should be:InfoKioskInfoKioskCorporate GuidelinesCorporate IdentityThanks in advance |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 05:16:34
|
quote: Originally posted by deekshan Thanks for your reply.But its returning NULLEg:My column is \MCD\Categories\InfoKiosk\Communication\1.htm\MCD\Categories\InfoKiosk\Communication\2.htm\MCD\Categories\Corporate Guidelines\Booking Form for Penthouse at JTC Summit.doc\MCD\Categories\Corporate Identity\guidelines_for_use_of_new_jtc_lo.htmMy output should be:InfoKioskInfoKioskCorporate GuidelinesCorporate IdentityThanks in advance
SELECT LEFT(REPLACE(col,'\MCD\Categories\',''),CHARINDEX('\',REPLACE(col,'\MCD\Categories\',''))-1) FROM YourTable |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-22 : 05:21:13
|
quote: Originally posted by deekshan Thanks for your reply.But its returning NULLEg:My column is \MCD\Categories\InfoKiosk\Communication\1.htm\MCD\Categories\InfoKiosk\Communication\2.htm\MCD\Categories\Corporate Guidelines\Booking Form for Penthouse at JTC Summit.doc\MCD\Categories\Corporate Identity\guidelines_for_use_of_new_jtc_lo.htmMy output should be:InfoKioskInfoKioskCorporate GuidelinesCorporate IdentityThanks in advance
In your question you didnt specify that it would start with \ MadhivananFailing to plan is Planning to fail |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-22 : 05:24:36
|
orSELECT Col1, PARSENAME(REPLACE(REPLACE(SUBSTRING(Col1,2,LEN(Col1)),'.', ''),'\','.'), 2)FROM @Sample MadhivananFailing to plan is Planning to fail |
 |
|
deekshan
Starting Member
5 Posts |
Posted - 2008-09-22 : 05:33:57
|
Thanks for your reply.I got the output.If MCD is the value which has been passed as an parameter in the stored procedure then how the statement will be.Actually MCD is the parameter which i pass before executing the stored procedure.That part i have completed before. but its a variable one which varies for different departments as per my input parameter(MCD is the department name)Thanks in advance |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 05:44:25
|
quote: Originally posted by deekshan Thanks for your reply.I got the output.If MCD is the value which has been passed as an parameter in the stored procedure then how the statement will be.Actually MCD is the parameter which i pass before executing the stored procedure.That part i have completed before. but its a variable one which varies for different departments as per my input parameter(MCD is the department name)Thanks in advance
what should be your output when you pass MCD as deptname? |
 |
|
deekshan
Starting Member
5 Posts |
Posted - 2008-09-22 : 06:00:36
|
Output must be same. It should be after categories and '\' |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 06:05:06
|
quote: Originally posted by deekshan Output must be same. It should be after categories and '\'
and return only ones having that deptname in path? |
 |
|
deekshan
Starting Member
5 Posts |
Posted - 2008-09-22 : 06:05:29
|
Thanks. I changed MCD to parameter nameNow its works as per the input parameter |
 |
|
|