SQL Query for Update Column
-
Hi all, I uploaded some data to SQL Server 2008 from Excel.The table has 4 Fields,After upload the data to Database some of the data in fourth fields are NULL.I need to update the data from first as follows Field1 , Field2 , Field3 , Field4 ABC_XYZ_123 , Office , 432322 , Null XYV_PVC_321 , House , 908000 , 321 MBV_DHC_908 , House , 751232 , 908 MNP_BNM_876 , Office , 125152 , 876 As mentioned above,I need to update first row with 123 which already have in first field. please help me to find to query for solvng above issue. thanks
-
Hi all, I uploaded some data to SQL Server 2008 from Excel.The table has 4 Fields,After upload the data to Database some of the data in fourth fields are NULL.I need to update the data from first as follows Field1 , Field2 , Field3 , Field4 ABC_XYZ_123 , Office , 432322 , Null XYV_PVC_321 , House , 908000 , 321 MBV_DHC_908 , House , 751232 , 908 MNP_BNM_876 , Office , 125152 , 876 As mentioned above,I need to update first row with 123 which already have in first field. please help me to find to query for solvng above issue. thanks
here it is
UPDATE mytable
SET field4 =
(SELECT RIGHT(mt.field1,CHARINDEX('_',mt.field1)-1)
FROM mytable mt
WHERE mt.field1 = mytable.field1
)SELECT * FROM mytable
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com
-
here it is
UPDATE mytable
SET field4 =
(SELECT RIGHT(mt.field1,CHARINDEX('_',mt.field1)-1)
FROM mytable mt
WHERE mt.field1 = mytable.field1
)SELECT * FROM mytable
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com
thanks for you reply.let me try with it
-
thanks for you reply.let me try with it
That should works without problem, I tested it and it worked.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com
-
That should works without problem, I tested it and it worked.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com
Hello, I tried with above query.But it extracting 10 Digits.I dont know why.I have some datas in Field4 like this "74_125352" actually i need 125352.
modified on Sunday, May 8, 2011 1:46 AM