Sql-server – Return Output from SQL Function using command line SQLCMD

sql-server-2008

I have a SQL Function that returns an Integer as the Output. I need to execute it via sqlcmd and I only want to get it's integer output.

However right now I'm getting back this type of output:

------------ 
      25 

<1 rows affected> 

How can I get my output to be just 25 with no other text.

Here's the Call I'm using:

sqlcmd -S MyServer\Instance -d SQLAdmin -Q "SELECT dbo.UDF_INT_Get_Status ('INT_02')"  

Best Answer

You are looking for the headers option of sqlcmd. Adding -h -1 will suppress header information.

sqlcmd -S MyServer\Instance -d SQLAdmin -Q "SELECT dbo.UDF_INT_Get_Status ('INT_02')" -h -1