Search the Community
Showing results for tags 'SUBSTRING'.
Found 4 results
Hi, I am trying to join two tables that have similar fields, but in slightly different formats. I was previously using something along the lines of like '%*%' Then SUBSTRING(b.fieldname,CHARINDEX(b.fieldname,'*',1)+1,9) However the format has now changed and I am struggling to put something together. Table A BD8K1 23161*35*201904231110*QULN Table B 23161*35*1 However the number of characters in both could vary so cant use that. Table A BD8K1 242875*10*201904251015*NBB1 Table B 242875*10*113 Is there some code that could be written that's something like: A – From the space use the value up to and including the 2nd * (BD8K1 is at the beginning of every value in table A so could potentially use from character 7) B – Use the value up to and including the 2nd * Any help would be very much appreciated. Thanks James
I am teaching a course on the ACSL competition to middle school students and my programming skills are little rusty. In the next competition we have a programming challenge where they need to create a program that you can input a string and several substring parameters. The problem is that they need to be able to input a negative number and have it produce the desired result. For example: with the string "Hello world!" input 1: 0, -1 output 1: Hello world input 2: 0,-5 output 2: Hello w input 3: -4,0 output 3: rld! I am at a little bit of a loss as how to go about getting the desired output.
I am trying to process a string which contains various data relating to an elearning record; Moodle SCORM suspend_data if you're familiar with it Since I do not have access to server side SQL/CLR functions through the Moodle interface, I am attempting to reference, and extract, the relevant information from the string by explicitly referencing the character locations of the information I need in the string and then converting them as required so they can be summed e.g. SELECT prefix_user.username,........ ((CASE(SUBSTRING(value_rep,237,1)) WHEN 'c' THEN 1 ELSE 0 END) + ........(CASE(SUBSTRING(value_rep,3659,1)) WHEN 'c' THEN 1 ELSE 0 END)) AS "# Videos watched"........FROM ((prefix_user LEFT JOIN (SELECT prefix_scorm_scoes_track.userid, Replace(value,"''","'XX'") AS value_repFROM prefix_scorm_scoes_track WHERE (((prefix_scorm_scoes_track.element)='cmi.suspend_data'))) AS vid ON prefix_user.id = vid.userid The string contains multiple occurrences of the string patterns '','n' and 'nn' where n is any digit 0-9 which I need to replace with the same string pattern e.g. 'XX', so that the total length of the string as a whole remains the same. I Initially thought that the pattern would always exist as '' or 'nn' so it was relatively simple to use a REPLACE(value,"''","XX") I understand it's not possible to use regex in the REPLACE function and have been investigating the use of PATINDEX with STUFF, but understand this is inly suitable for operating on 1 occurrence of a pattern. The report can be output to a CSV for viewing in Excel, so my conclusion is currently to carry out post-processing with Excel VBA where I will have access to loops and other functions. Is what I am trying to achieve possible without the use of a function on the SQL server?
SELECT SUBSTRING ( Name, CHARINDEX ( ' ', Name ) + 1, LEN ( Name ) ) + ', ' + SUBSTRING ( Name, 1, CHARINDEX ( ' ', Name ) ) as 'Name' Hai guys. The code is about putting the last name to the front, the last name to the back, and put coma(,) in the middle. But, the code was to complicated for me. Can you please explaine it to me or maybe give other code that is much simpler and if you could with some explanation. I'm new to the SQL. Thankyou.