Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tech-notes:sql [2022/12/21 14:00] gerardorourketech-notes:sql [2022/12/21 14:06] (current) – [SUBSTRING and CHARINDEX] gerardorourke
Line 308: Line 308:
  
   *https://docs.microsoft.com/en-us/sql/t-sql/language-elements/exists-transact-sql?view=sql-server-ver15   *https://docs.microsoft.com/en-us/sql/t-sql/language-elements/exists-transact-sql?view=sql-server-ver15
 +
 +===== SUBSTRING and CHARINDEX =====
 +
 +Here we have a column 'myColumn' with a comma separated value of (for example) 'apples,bananas' and we want FirstVariable = 'apples' and SecondVariable = 'bananas'
 +<code>
 +[FirstVariable] = SUBSTRING([myColumn],1,(CHARINDEX(',',[myColumn])-1))
 +[SecondVariable] = SUBSTRING([myColumn],(CHARINDEX(',',[myColumn])+1),100)
 +</code>
 +
 +CHARINDEX find the comma and lets you know the position it is in.
 +SUBSTRING uses start and end position to extract a substring.
  • tech-notes/sql.1671631212.txt.gz
  • Last modified: 2022/12/21 14:00
  • by gerardorourke