Home > database >  The update consult
The update consult

Time:12-22



A/the 14th floor village name/high/2 unit area
A/the 14th floor village name/2 unit/low area
A/f/2 unit 13 village name/high area
A/f/2 unit 13 village name/low area

Want to update into as follows, building date is change

Village name a high area high/14th floor/2 unit/area
A low area/14 village name low f/2 unit/area
Village name a high area/building/2 unit 13/high area
A low area/floor 13 village name/2 unit/low area

CodePudding user response:

 
The CREATE TABLE # A
(
The NAME VARCHAR (200)
)
# INSERT INTO A VALUES (' A village name/14th floor high/2 unit/area ')
# INSERT INTO A VALUES (' village name A low f/2 unit/area/14 ')
# INSERT INTO A VALUES (' A/f/2, 13 village name high unit/area ')
# INSERT INTO A VALUES (' A/f/2 unit 13 village name/low area ')

SELECT the LEFT (A.N AME, CHARINDEX ('/', A.N AME) - 1) + RIGHT (A.N AME, 2) + the SUBSTRING (A.N AME, CHARINDEX ('/', A.N AME), 999) FROM # aa

DROP TABLE # A

CodePudding user response:

Borrow # 1 data:
 SELECT PARSENAME (REPLACE ([Name], '/', '. '), 4) + PARSENAME (REPLACE ([Name], '/', '. '), 1) 
+ '/' + PARSENAME (REPLACE ([Name], '/', '. '), 3)
+ '/' + PARSENAME (REPLACE ([Name], '/', '. '), 2)
+ '/' + PARSENAME (REPLACE ([Name], '/', '. '), 1)
The FROM # aa

CodePudding user response:

reference 1/f, kun jins kao kun jins kao response:
 
The CREATE TABLE # A
(
The NAME VARCHAR (200)
)
# INSERT INTO A VALUES (' A village name/14th floor high/2 unit/area ')
# INSERT INTO A VALUES (' village name A low f/2 unit/area/14 ')
# INSERT INTO A VALUES (' A/f/2, 13 village name high unit/area ')
# INSERT INTO A VALUES (' A/f/2 unit 13 village name/low area ')

SELECT the LEFT (A.N AME, CHARINDEX ('/', A.N AME) - 1) + RIGHT (A.N AME, 2) + the SUBSTRING (A.N AME, CHARINDEX ('/', A.N AME), 999) FROM # aa

DROP TABLE # A


If I want to find out the result of another column is inserted into the how to operate

CodePudding user response:

reference zk12668 reply: 3/f
Quote: refer to 1st floor kun jins kao kun jins kao response:
 
The CREATE TABLE # A
(
The NAME VARCHAR (200)
)
# INSERT INTO A VALUES (' A village name/14th floor high/2 unit/area ')
# INSERT INTO A VALUES (' village name A low f/2 unit/area/14 ')
# INSERT INTO A VALUES (' A/f/2, 13 village name high unit/area ')
# INSERT INTO A VALUES (' A/f/2 unit 13 village name/low area ')

SELECT the LEFT (A.N AME, CHARINDEX ('/', A.N AME) - 1) + RIGHT (A.N AME, 2) + the SUBSTRING (A.N AME, CHARINDEX ('/', A.N AME), 999) FROM # aa

DROP TABLE # A


If I want to find out the result of another column is inserted into the how to operate?

Into which a list
On the basis of the original table new column

CodePudding user response:

 
The CREATE TABLE # A
(
The NAME VARCHAR (200)
)
# INSERT INTO A VALUES (' A village name/14th floor high/2 unit/area ')
# INSERT INTO A VALUES (' village name A low f/2 unit/area/14 ')
# INSERT INTO A VALUES (' A/f/2, 13 village name high unit/area ')
# INSERT INTO A VALUES (' A/f/2 unit 13 village name/low area ')
- a list of new
The ALTER TABLE # A ADD NEWCOLUMN VARCHAR (300)
- UPDATE the new column
UPDATE # A SET NEWCOLUMN=LEFT (NAME, CHARINDEX ('/', NAME) - 1), (NAME, 2) + + RIGHT SUBSTRING (NAME, CHARINDEX ('/', NAME), 999)
SELECT * FROM # A
DROP TABLE # A

  • Related