创建以逗号分隔的已检查位值列表

时间:2017-01-24 03:27:19

标签: sql sql-server tsql sql-server-2012

我有一张类似于以下内容的表格:

Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/LocalBroadcastManager;
       at com.strinkle.warble.lqDiqe.WvKvFq(Unknown Source)
       at com.strinkle.warble.PreProcActivity.ZqNgdX(Unknown Source)
       at com.strinkle.warble.PreProcActivity.onCreate(Unknown Source)
       at android.app.Activity.performCreate(Activity.java:5976)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
       at android.app.ActivityThread.access$800(ActivityThread.java:145)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5319)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.LocalBroadcastManager" on path: DexPathList[[zip file "/mnt/asec/com.tesseractmobile.solitairemulti-2/base.apk", zip file "/data/data/com.tesseractmobile.solitairemulti/app_app_apk/solitairemulti.dat.jar"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
       at com.strinkle.warble.lqDiqe.WvKvFq(Unknown Source)
       at com.strinkle.warble.PreProcActivity.ZqNgdX(Unknown Source)
       at com.strinkle.warble.PreProcActivity.onCreate(Unknown Source)
       at android.app.Activity.performCreate(Activity.java:5976)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
       at android.app.ActivityThread.access$800(ActivityThread.java:145)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5319)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

使用存储过程我需要创建一个逗号分隔的位值列表,这些列值是真的(因此,如果FuelCard为1,我的结果将为CREATE TABLE [dbo].[TestTable] ( [Id] INT NOT NULL, [FoodCard] BIT NULL, [FuelCard] BIT NULL, [GoCard] BIT NULL, [Created] DATETIME NOT NULL, [CreatedBY] VARCHAR (150) NOT NULL, [Modified] DATETIME NULL, [ModifiedBy] VARCHAR (150) NULL, [PaymentTotal] DECIMAL (10, 2) NULL ); ,但如果FuelCard和FoodCard为1,我的结果将是{{ 1}}。在我的实际表中,我有大约12位值可以使用。

我已经考虑过使用一系列的case语句来创建我的逗号分隔列表,但这样做似乎非常糟糕。解决这个问题的更好方法是什么?

1 个答案:

答案 0 :(得分:2)

您可以使用case执行此操作:

select stuff( (case when FoodCard = 1 then ', FoodCard' else '' end) +
              (case when FuelCard = 1 then ', FuelCard' else '' end) +
              (case when GoCard = 1 then ', GoCard' else '' end) +
              . . .,
              1, 2, '') as cardList

stuff()删除前两个字符,即', '