我有以下存储过程:
Create PROCEDURE [dbo].[GETVendorsStatsAgainstSearTerm]
@Date DateTime ,
@SearchId bigint
AS
declare @cmd as varchar(2000)
set @cmd = ' select *, ' + cast(SearchId as varchar) + ' as SearhId from tbl'
exec (@cmd)
我想将SearchId
视为要运行select查询的列。我想知道SearchId
列的正确类型。
我无法将此SearchId
列转换为C#中的长数据类型。有人能帮助我吗?
答案 0 :(得分:0)
您可以尝试使用Convert function
Convert(varchar(50),SearchId )
答案 1 :(得分:0)
我想问题是有一些未分配的SearchId会导致将一个null转换为varchar。
尝试这样的事情:
//...
set @cmd = CASE
WHEN (SearchId IS NOT NULL) THEN (' select *, ' + cast(SearchId as varchar) + ' as SearhId from tbl')
ELSE ' select *, 0 as SearhId from tbl'
END
///...