VB script

Greeting,

I have a txt file and its col1 contains a list of values.
I also have the following sql.

select count(*)
from TBL
where bldg in(xxx);

I need a script to append col1 to xxx and seperate by comma)

Thanks in advance.
mrongAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

x-menIT super heroCommented:
you can use powershell to "build" the SQL script:

PS>"select count(*) from TBL where bldg in (xxx" > SQLscript.sql
PS> gc col1.txt | % {write-host -nonewline ",$_" >> SQLscript.sql}
PS> ")" >> SQLscript.sql
0
mrongAuthor Commented:
what changes need to be done if I want to sub TBL with col1 in another txt?
thanks.
0
mrongAuthor Commented:
x-men,

I tried your suggestion and got the SQLscript.sql with the following data. It didn't sub xxx with col1.txt

select count(*) from TBL where bldg in (xxx
)
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

x-menIT super heroCommented:
col1.txt should have one value per row. The command  "PS> gc col1.txt" (Get-Content)  should return the contents of the file.


PS>"select count(*) from TBL where bldg in (" > SQLscript.sql
PS> gc col1.txt | % {write-host -nonewline ",$_" >> SQLscript.sql}
PS> ")" >> SQLscript.sql
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrongAuthor Commented:
Yes, col1.txt has one value per row and  the command  "PS> gc col1.txt" (Get-Content)  did returned the contents of the file. but it didn't put the values into SQLscript.sql.
0
x-menIT super heroCommented:
yes, sorry:

 gc col1.txt | % {$x=$x+",$_"};$x >> SQLscript.sql}
0
mrongAuthor Commented:
So the complete code should be the followings? thx

PS>"select count(*) from TBL where bldg in (" > SQLscript.sql
PS> gc col1.txt | % {$x=$x+",$_"};$x >> SQLscript.sql}
PS> ")" >> SQLscript.sql
0
x-menIT super heroCommented:
yes, note that there will be a "," that needs to be deleted.

"...TBL where bldg in (,ABC,SDF,..."
                                         ^
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.