2015年1月22日

T-SQL - Parameter + Like語法

此功能是在打開頁面前先到資料表搜尋最大值,Select完後將資料丟進DataTable
該欄位為字串型態,寫法如下:

DbAgent sqlHelper = new DbAgent();
DbCommand sqlValue = sqlHelper.getDbCommand(m_ConfigDBName);
StringBuilder sqlstr = new StringBuilder();
SqlParameter par;

sqlValue.CommandText = @"SELECT MAX(CALL_NO) as MAXCALLNO 
                                            FROM NAM_NAME(nolock) 
                                            WHERE CALL_NO LIKE '%' + @CALL_NO +'%' ";

            par = new SqlParameter("CALL_NO", SqlDbType.NVarChar);
            par.Value = pYear;
            sqlValue.Parameters.Add(par);

            try
            {
                DataTable dt = sqlHelper.QueryToDataTable(sqlValue, pInfo);

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

沒有留言:

張貼留言

<Javascript> How to uncompressed GZIP at front-end using Javascript

It's been a while I haven't share my coding work. In this article I would like to share how to receive a Gzip file via stream, unzip...