0

I have the below SQL query. I wanted to execute the same query in , but am not able convert it and not getting proper result. Can I get the correct convert format?

SELECT distinct CASE 
WHEN enty_typ_cd = 'acct' THEN 'Account : '
WHEN enty_typ_cd = 'pfolio' THEN 'Portfolo : '
END +
a.mstr_shrt_nm_id as [ ]
FROM RCMglbl..nav_nt a, RCMglbl..enty_mstr b
WHERE a.enty_id = b.id AND office = 'sf'
AND mnth_end_dt <> (select lst_mo_end_dt from RCMglbl..proc_dt)
AND mnth_end_dt is not NULL
2
  • 2
    What code do you have so far for your script? What error do you get?
    – Matt Wilko
    Commented May 17, 2013 at 9:55
  • 1
    The SQL query itself is not going to change, just because you run it from a different environmen (VBScript in this case). Commented May 17, 2013 at 10:05

1 Answer 1

1

Im not sure what you mean by converting the string to an VBscript... Like the Ansgar Wiechers said, the string remains the same, the environment changes
anyway...
Place this code in notepad.exe
edit the connection string to suit your server
save file with .vbs extension
locate it and run it!

Const adUseClient = 3
Dim cn
Set cn = CreateObject("ADODB.Connection")

dim sql
sql = "SELECT distinct CASE " & _
        "WHEN enty_typ_cd = 'acct' THEN 'Account : ' " & _ 
        "WHEN enty_typ_cd = 'pfolio' THEN 'Portfolo : ' " & _ 
        "END + a.mstr_shrt_nm_id as [ ] " & _
        "FROM RCMglbl..nav_nt a, RCMglbl..enty_mstr b " & _ 
        "WHERE a.enty_id = b.id AND office = 'sf' " & _ 
        "AND mnth_end_dt <> (select lst_mo_end_dt from RCMglbl..proc_dt) " & _
        "AND mnth_end_dt is not NULL"
with cn 
    .CursorLocation = adUseClient
    .Open "Driver={SQL Server};Server=SERVER_NAME; Database=DATABASE_NAME; UID=USER_ID_NAME; PWD=PASSWORD"
    .CommandTimeout = 0
    .Execute(sql)
end with

cn.close
set cn = Nothing

Once you get that working, youve gotta think about the result your getting from your query... therefore, i advise on reading more about SELECT STATEMENT and possibly a RECORDSET

2
  • 2
    VBScript doesn't know a constant adUseClient, so it must be defined as Const adUseClient = 3. Commented May 17, 2013 at 11:43
  • @AnsgarWiechers yes! i totally forgot ( been writing macros in vba all morning ), nice catch!
    – user2140173
    Commented May 17, 2013 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.