I'm trying to use sqlcmd utility and the query is working I'm just wondering how I can get just the value without fieldname and those dashes?
$res = sqlcmd -Q @"
:Connect .
use [Database1]
select firstname from customer
"@
$res
Output:
firstname
--------------------------------------------------
John
You need -h -1
, -m 1
and set nocount on;
Try this:
$res = sqlcmd -S . -m 1 -h -1 -Q @"
use [Database1];
set nocount on;
select firstname from customer;
"@