0

重複の可能性:
SQLで月名を月番号関数に変換する

以下のスクリプトの領域で、月の名前を月の番号に変換しようとしていますdatename(MM, patientinfo.PatientDOB)。例として、現在asを返しているので、またはJanuaryとして返したいと思います。011

私が読んだことから、私はをする必要があるかもしれませんがCASE WHEN 'January' THEN 1、それをどこに挿入するか、または使用する正確な構文がわかりません。

select
    Update_Log.RecordID as 'Dictation ID',
    cast(dictations.DOS as DATE) as 'Date of Service',
    groups.GroupName,
    rtrim(aspnet_Users.Firstname)+' '+rtrim(aspnet_Users.LastName) as Provider, 
    Update_Log.Updated, 
    Update_XRef.columnName as 'Update Type', 
    "New Value" =
        case 
            when update_xref.columnname = 'FacilityID' then (select facility.FacilityName+' [gID:'+update_log.NewValue+']' from facility where update_log.NewValue = facility.FacilityID)
            when update_xref.columnname = 'DOS' then (select left(update_log.NewValue, 11) as 'New Value')
            when update_xref.columnname = 'DictatorID' then (select rtrim(aspnet_users.Firstname)+' '+rtrim(aspnet_users.lastname) from aspnet_Users where aspnet_users.userid1 = update_log.UpdatedBy)
            when update_xref.columnname = 'PatientID' then (select rtrim(patientinfo.PatientFirst)+' '+rtrim(patientinfo.PatientLast)+' ['+datename(MM, patientinfo.PatientDOB)+'/'+datename(DD, patientinfo.PatientDOB)+'/'+datename(YY, patientinfo.PatientDOB)+ ', gID:'+rtrim(patientinfo.PatientID)+']' from patientinfo where patientinfo.PatientID = Update_Log.NewValue)
        end,
    "Old Value" =
        case 
            when update_xref.columnname = 'FacilityID' then (select facility.FacilityName+' [gID:'+update_log.OldValue+']' from facility where update_log.OldValue = facility.FacilityID)
            when update_xref.columnname = 'DOS' then (select left(update_log.OldValue, 11) as 'Old Value')
            when update_xref.columnname = 'DictatorID' then (select rtrim(aspnet_users.Firstname)+' '+rtrim(aspnet_users.lastname) from aspnet_Users where aspnet_users.userid1 = update_log.UpdatedBy)
            when update_xref.columnname = 'PatientID' then (select rtrim(patientinfo.PatientFirst)+' '+rtrim(patientinfo.PatientLast)+' ['+left(datename(MM, patientinfo.PatientDOB),3)+'/'+datename(DD, patientinfo.PatientDOB)+'/'+datename(YY, patientinfo.PatientDOB)+ ', gID:'+rtrim(patientinfo.PatientID)+']' from patientinfo where patientinfo.PatientID = Update_Log.OldValue)
        End
from 
    Update_Log, 
    Update_XRef, 
    aspnet_Users, 
    groups, 
    Dictations
where 
    Update_log.XRefID = Update_XRef.xRefID
    and Update_Log.UpdatedBy = aspnet_Users.userid1
    and aspnet_users.Groupid = Groups.GroupID
    and dictations.Dictationid = Update_Log.RecordID
    and Update_Log.Updated > dictations.DateofSignature
order by 
    groups.GroupName, 
    aspnet_users.LastName, 
    update_log.RecordID
4

2 に答える 2

3

patientinfo.PatientDOB日付の整数の月の部分を取得するために、完全な入力された日付であると仮定します。

datepart(MM, patientinfo.PatientDOB)

また

month(patientinfo.PatientDOB)

cast(?? as varchar(2))文字列にラップされます。

于 2012-10-30T14:58:50.833 に答える
0

私は以前ここでこれに答えました:

SQLServerで月名を月番号に変換する

これがあなたのために働くかどうか私に知らせてください!

于 2012-10-30T15:39:09.443 に答える