daily pastebin goal
79%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Table
  2. CREATE TABLE #TempTable (
  3.     Name text,
  4.     UnitID text,
  5.     Country text,
  6.     HS text
  7. )
  8. INSERT INTO #TempTable
  9.     (Name, UnitID, Country, HS)
  10. VALUES
  11.     ('User1',  'U1',  'US', 30),
  12.     ('User2',  'U2',  'AS', 40),
  13.     ('User3',  'U3',  'AS', 50),
  14.     ('User4',  'U4',  'AS', 60),
  15.     ('User5',  'U5',  'AS', 80),
  16.     ('User6',  'U6',  'AS', 90),
  17.     ('User7',  'U7',  'AS', 10),
  18.     ('User8',  'U8',  'AS', 10),
  19.     ('User9',  'U9',  'AS', 20),
  20.     ('User10', 'U10', 'AS', 30),
  21.     ('User11', 'U11', 'AS', 40),
  22.     ('User12', 'U12', 'AS', 70)
  23.    
  24. select * from schedules where substr(unitIndex, 2, 1) between '1' AND '3'
  25.    
  26. -- Table
  27. CREATE TABLE #TempTable (
  28.     Name varchar(50),
  29.     UnitID varchar(10),
  30.     Country varchar(2),
  31.     HS int
  32. )
  33. INSERT INTO #TempTable
  34.     (Name, UnitID, Country, HS)
  35. VALUES
  36.     ('User1',  'U1',  'US', 30),
  37.     ('User2',  'U2',  'AS', 40),
  38.     ('User3',  'U3',  'AS', 50),
  39.     ('User4',  'U4',  'AS', 60),
  40.     ('User5',  'U5',  'AS', 80),
  41.     ('User6',  'U6',  'AS', 90),
  42.     ('User7',  'U7',  'AS', 10),
  43.     ('User8',  'U8',  'AS', 10),
  44.     ('User9',  'U9',  'AS', 20),
  45.     ('User10', 'U10', 'AS', 30),
  46.     ('User11', 'U11', 'AS', 40),
  47.     ('User12', 'U12', 'AS', 70)
  48.  
  49. -- Update statement for all rows between U3 and U10
  50. UPDATE #TempTable
  51. SET HS = 1000
  52. WHERE CONVERT(int, STUFF(UnitID, 1, 1, '')) BETWEEN 3 AND 10
  53.  
  54. -- Result
  55. SELECT *
  56. FROM #TempTable
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top