SQLCMD Execute Multiple Stored Procedure with Parameters Dependent On Another

I am trying to use SQLCMD via command line to call 2 stored procedures which one is dependent on another.  Both stored procedures have parameters.  I can run 1 stored procedure with parameters, no problem.  

It's trying to combine the 2 together because stored procedure User.pSessionCreate executes a unique SessionGuid ID needed to run the 2nd stored procedure Custom.pTotport_AssetClass as one of the parameters.  In addition, the data results is output to a .txt file.  Thanks in advance for the help!

Here is an example of the SQLCMD I put together but I get the error "Cannot use the OUTPUT option when passing a constant to a stored procedure" in my output .txt file.  You'll see below the @SessionGuid created from the 1st stored procedure is needed in the 2nd stored procedure parameter.
sqlcmd -S serverName" -d dbName -E -h -1 -Q "set nocount on;declare @SessionGuid nvarchar(48) exec User.pSessionCreate 'login', 'password', '@SessionGuid';exec Custom.pTotport_AssetClass '@SessionGuid', 'Group', '2015-3-31', 'PC', 'IN'" -o C:\temp\test.txt

Open in new window

Here is a actual syntax when running out of SSMS directly and works just fine.  Just trying to accomplish this via SQLCMD for another process.  

declare @SessionGuid nvarchar(48)
exec User.pSessionCreate @loginname = 'login', @password='password',@SessionGuid = @SessionGuid out

exec Custom.pTotport_AssetClass
	@SessionGuid = @SessionGuid,
	@Portfolios = 'Group',
	@ThruDate = '2015-3-31',
	@ReportingCode = 'PC',
	@FileType = 'AA'

Open in new window

KANEDA 0149Asked:
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.

ste5anSenior DeveloperCommented:
Just run that. But instead of using a query string, use an input file. There can you place your T-SQL batch.

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
KANEDA 0149Author Commented:
Thank you so much ste5an that did it, why didn't I think of that...LOL
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
Programming

From novice to tech pro — start learning today.