Manipulate SQL String
-
Hi, I need help with selecting part of column value. Say that I have a database that return me a InventoryID InventoryID as123-CE123daf235 23d45543-CE23432 234dave-CEj324lio I want to select everything before -CE, i couldn't use Substring() function because each value have a different character id. can anyone advice me how to do this??? Thanks in advance!!!
-
Hi, I need help with selecting part of column value. Say that I have a database that return me a InventoryID InventoryID as123-CE123daf235 23d45543-CE23432 234dave-CEj324lio I want to select everything before -CE, i couldn't use Substring() function because each value have a different character id. can anyone advice me how to do this??? Thanks in advance!!!
-
Hi, I need help with selecting part of column value. Say that I have a database that return me a InventoryID InventoryID as123-CE123daf235 23d45543-CE23432 234dave-CEj324lio I want to select everything before -CE, i couldn't use Substring() function because each value have a different character id. can anyone advice me how to do this??? Thanks in advance!!!
-
select substring(InventoryID,1,CHARINDEX('CE',InventoryID)-2) from tablename
I Love T-SQL "Don't torture yourself,let the life to do it for you."
I have another small question regarding this: select substring(inventoryId,1,Charindex('-CE',InventoryID)) from Inventory work if all the inventoryID contain -CE, however there're some inventoryID that doesn't contain -CE and for those that doesn't contain -CE i want to select the whole field. My SQL statement is really big, if i use If..Else statement then it's like if InventoryID like '-CE' begin .....the whole nine yard of select statement... else .....another nine yard of select statement.... i was wonder if you can use if within select statement...what i picture are: SELECT *, (inventoryid without -CE for those that contain -CE) FROM Inventory I hope you understand my question. Thanks!
-
I have another small question regarding this: select substring(inventoryId,1,Charindex('-CE',InventoryID)) from Inventory work if all the inventoryID contain -CE, however there're some inventoryID that doesn't contain -CE and for those that doesn't contain -CE i want to select the whole field. My SQL statement is really big, if i use If..Else statement then it's like if InventoryID like '-CE' begin .....the whole nine yard of select statement... else .....another nine yard of select statement.... i was wonder if you can use if within select statement...what i picture are: SELECT *, (inventoryid without -CE for those that contain -CE) FROM Inventory I hope you understand my question. Thanks!
InventoryID contain values like this: 23d45543CE23432 23d45543-CE23432 73d45543CE23434 73d45543-CE23434 ... and so on Try T-SQL down below I think it will work for you.
select case when CHARINDEX('-CE',inventoryid ) =0 then inventoryid else substring(inventoryid ,1,CHARINDEX('-CE',inventoryid )-1) end as inventoryID from Inventory
I Love T-SQL "Don't torture yourself,let the life to do it for you."
-
InventoryID contain values like this: 23d45543CE23432 23d45543-CE23432 73d45543CE23434 73d45543-CE23434 ... and so on Try T-SQL down below I think it will work for you.
select case when CHARINDEX('-CE',inventoryid ) =0 then inventoryid else substring(inventoryid ,1,CHARINDEX('-CE',inventoryid )-1) end as inventoryID from Inventory
I Love T-SQL "Don't torture yourself,let the life to do it for you."