我有一个值,我需要在它以3开头时进行转换,然后将该值与另一个字段组合以创建最终值。
到目前为止代码:
,case
when b.thing like '3%' then '000'
else b.thing
end as 'Thing'
然后我想使用' Thing'值得创造' Thing + b.Stuff'。我试着添加' b.Stuff'到else语句但只返回' b .Thing'。
我想我可能需要创建一个子查询/内联视图,但我不知道该怎么做。
答案 0 :(得分:0)
您应该只能在代码中添加b.stuff(假设它们是相同的数据类型)
var cart : Cart
let requiredName = pNam[indexPath.row].description
let entityDescription = NSEntityDescription.entityForName("Cart", inManagedObjectContext: managedObjectContext!)
let fetchRequest = NSFetchRequest()
fetchRequest.entity = entityDescription!
fetchRequest.predicate = NSPredicate(format:"pName == %@",requiredName)
do {
let results = try self.managedObjectContext?.executeFetchRequest(fetchRequest) as! [Cart]
if results.count == 0 { // not found, so create new...
cart = Cart(entity: entityDescription!, insertIntoManagedObjectContext: managedObjectContext)
cart.pName = requiredName
} else { // found at least one, so use the first...
cart = results[0]
}
// Now update the other attribute values:
cart.pCost = pCst[indexPath.row].integerValue!
cart.pQuantity = pQty[indexPath.row].integerValue!
cart.orderID = pObjectID[indexPath.row].description
} catch {
print("Error fetching")
}