0

I have table in database which stores few queries, Using sqlcmd I am trying to retrieve the queries. While doing so, the select * from abc is getting replaced with 'select from abc'

How to overcome this issue?

Edit:

Max_Values=5
n=1
while [ $n -le $Max_Values ]
do
Sql_Qry="set nocount on;Select Query from dbo.abc With(nolock) Where RowID=$n"  

Query=`/opt/mssql-tools/bin/sqlcmd -S Server_name -U UserID -P Password -d database -Q "$Sql_Qry" -h -1`
echo $Query
n=$(( n+1 ))
done

Expected Output:

Select * from Int.Table1

Actual Output:

Select Script1.txt script2.sh script3.sh from Int.Table1

The script1, script2 and script3 are files within the current directory

6
  • 2
    Correct quoting is the answer. Please edit your question to show us the whole command you're trying to run. Commented Jan 10, 2020 at 8:19
  • @Panki Please refer the the Edit Commented Jan 10, 2020 at 9:24
  • echo "$Query", maybe? Always quote your variables. Commented Jan 10, 2020 at 9:27
  • @AlexP Thanks, that fixed it Commented Jan 10, 2020 at 10:20
  • You haven't got * in your query. Does your question title actually reflect the question being asked? Commented Jan 10, 2020 at 10:21

1 Answer 1

0

Double quote the variable that you want to print will fix the problem. i.e.

echo "$Query"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.