Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2002
    Posts
    4

    Unanswered: unix with embeded sybase sql code

    Need to run sybase sql code under unix and return info back to unix var.
    Anybody knows how to do this and why the following code is not working?
    DATE1=
    ${sybasebin}/isql -U${DBUSER} -S${DSQUERY} <<EOF
    ${DBPASSWD}
    use ${DB}
    go

    declare @effective_date datetime
    select @effective_date=dateadd(dd, -1, convert(datetime, convert(varchar(10), getdate(),112)))
    select "${DATE1}" = @effective_date
    go
    EOF
    echo "Date = ${DATE1} \n"

  2. #2
    Join Date
    Sep 2002
    Location
    Germany, near Aachen
    Posts
    120

    Re: unix with embeded sybase sql code

    Originally posted by j1c4b
    Need to run sybase sql code under unix and return info back to unix var.
    Anybody knows how to do this and why the following code is not working?
    DATE1=
    ${sybasebin}/isql -U${DBUSER} -S${DSQUERY} <<EOF
    ${DBPASSWD}
    use ${DB}
    go

    declare @effective_date datetime
    select @effective_date=dateadd(dd, -1, convert(datetime, convert(varchar(10), getdate(),112)))
    select "${DATE1}" = @effective_date
    go
    EOF
    echo "Date = ${DATE1} \n"
    You need to use backticks to get the result of isql into a variable. And you need to get rid of the headers and the counting. Try this:

    DATE1=`isql -b -Usa -SPQ749DUD10 -P2hard4u <<EOF
    set nocount on
    go

    select dateadd(dd, -1, convert(datetime, convert(varchar(10), getdate(),112)))
    go
    EOF
    `

    echo "Date = ${DATE1} \n"

    The -b tells isql to switch of headings.
    The 'set nocount on' prevents row counting.
    You don't need a variable to hold the result, you can use the result directly.
    Additionally you have to put the password on the isql command or you will get 'Password:' into your DATE1 variable.

  3. #3
    Join Date
    Mar 2002
    Posts
    4
    Thank you very much. Sorry for not replying

  4. #4
    Join Date
    Jun 2013
    Posts
    5

    set no count not working

    I had the same problem but after seeing this post i am able to assign it to a varibale but the problem is the No of rows affected is still coming. even after setting the nocount on

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •