01-30-2009
sql variable as array index
hi folks
i am facing problom while trying to access sql variable as array index ina unix shell script....script goes as below..
#!/bin/ksh
MAX=3
for elem in alpha beeta gaama
do
arr[$x]=$elem
((x=x+1))
Done
SQL_SERVER='servername'
/apps/sun5/utils/sqsh -S $SQL_SERVER -U user -P pwd -b -h <<EOF
set nocount on
go
use DBname
go
declare @MaxID int
set @MaxID=0
print $MAX
while @MaxID < $MAX
begin
print ${arr[@MaxID]}
set @MaxID=@MaxID+1
end
print 'endof while'
go
EOF
Is the script...
Prob is not able to use @MaxId as array subscript since it is a sql variable and array is used inside sqsh mode i.e sql prompt ...
Any way to access the unix array in side sql prompt based on index....???? Hope i made my self clear.
Thanks in advance.
10 More Discussions You Might Find Interesting
1. Filesystems, Disks and Memory
why do inode indices starts from 1 unlike array indexes which starts from 0
its a question from "the design of unix operating system" of maurice j bach
id be glad if i get to know the answer quickly
:) (0 Replies)
Discussion started by: sairamdevotee
0 Replies
2. UNIX for Dummies Questions & Answers
brothers why inode index starts from 1 unlike array inex which starts from 0
its a question from the design of unix operating system of maurice j.bach
i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies
3. Shell Programming and Scripting
I come across the problems when assigning the array in the script below . How to use the array with the 'string index' correctly ? When I assign a new string index , the array elements that are previously assigned are all changed .:eek::eek::eek:
$ array=211
$ echo ${array}
211
$... (4 Replies)
Discussion started by: youareapkman
4 Replies
4. Shell Programming and Scripting
$ cat file.txt
A|X|20
A|Y|20
A|X|30
A|Z|20
B|X|10
A|Y|40
Summing up $NF based on first 2 fields,
$ awk -F "|" 'BEGIN {OFS="|"}
{ sum += $NF }
END { for (f in sum) print f,sum }
' file.txt
o/p:
A|X|50
A|Y|60
A|Z|20 (4 Replies)
Discussion started by: uwork72
4 Replies
5. Shell Programming and Scripting
Hi,
I'm just trying to use a dynamic index for some array elements that I'm accessing within a loop. Specifically, I want to access an array at variable position $counter and then also at location $counter + 1 and $counter + 2 (the second and third array positions after it) but I keep getting... (0 Replies)
Discussion started by: weak_code-fu
0 Replies
6. Shell Programming and Scripting
Hi,
I am using KSH shell to do some programming.
I want to search array and print index value of the array.
Example..
nodeval4workflow="DESCRIPTION ="" ISENABLED ="YES" ISVALID ="YES" NAME="TESTVALIDATION"
set -A strwfVar $nodeval4workflow
strwfVar=DESCRIPTION=""... (1 Reply)
Discussion started by: tmalik79
1 Replies
7. Shell Programming and Scripting
Hi,
I need to update rows in a table based on the values in an array variable.
code is :
while read line
do
error_msg="$(echo $line)"
index=`expr $index+1`
done <"logs/$ffile"
rows_count=${#error_msg
}
i=0
while
do
echo "error msgs is... (2 Replies)
Discussion started by: RP09
2 Replies
8. Shell Programming and Scripting
Hi,
I am new to perl and I have the following query please help here.
I have following array variables declaration
@pld1 = qw(00 01 02 03 04 05);
@pld2 = qw(10 11 12 13 14 15);
for(my $k=1;$k<=2;$k++)
{
//I want here to use @pld1 if $k is 1
// and @pld2 if $k is 2. How to do... (3 Replies)
Discussion started by: janavan
3 Replies
9. Shell Programming and Scripting
I am trying to assign indexes to an associative array in a for loop but I have to use an eval command to make it work, this doesn't seem correct I don't have to do this with regular arrays
For example, the following assignment fails without the eval command:
#! /bin/bash
read -d "\0" -a... (19 Replies)
Discussion started by: Riker1204
19 Replies
10. Shell Programming and Scripting
Hello,
I have a complicated situational find and replace that I wrote in bash because I didn't know how to do everything in awk. The code works but is very slow, as expected.
To create my modified file, I am looping through an array that was populated earlier and making some replacements at... (6 Replies)
Discussion started by: LMHmedchem
6 Replies
LEARN ABOUT PHP
sqlsrv_field_metadata
SQLSRV_FIELD_METADATA(3) SQLSRV_FIELD_METADATA(3)
sqlsrv_field_metadata - Retrieves metadata for the fields of a statement prepared bysqlsrv_prepare(3)orsqlsrv_query(3)
SYNOPSIS
mixed sqlsrv_field_metadata (resource $stmt)
DESCRIPTION
Retrieves metadata for the fields of a statement prepared by sqlsrv_prepare(3) or sqlsrv_query(3). sqlsrv_field_metadata(3) can be called
on a statement before or after statement execution.
PARAMETERS
o $stmt
- The statment resource for which metadata is returned.
RETURN VALUES
Returns an array of arrays is returned on success. Otherwise, FALSE is returned. Each returned array is described by the following table:
Array returned by sqlsrv_field_metadata
+----------+---------------------------------------------------+
| Key | |
| | |
| | Description |
| | |
+----------+---------------------------------------------------+
| Name | |
| | |
| | The name of the field. |
| | |
| Type | |
| | |
| | The numeric value for the SQL type. |
| | |
| Size | |
| | |
| | The number of characters for fields of character |
| | type, the number of bytes for fields of binary |
| | type, or NULL for other types. |
| | |
|Precision | |
| | |
| | The precision for types of variable precision, |
| | NULL for other types. |
| | |
| Scale | |
| | |
| | The scale for types of variable scale, NULL for |
| | other types. |
| | |
|Nullable | |
| | |
| | An enumeration indicating whether the column is |
| | nullable, not nullable, or if it is not known. |
| | |
+----------+---------------------------------------------------+
For more information, see sqlsrv_field_metadata in the Microsoft SQLSRV documentation.
EXAMPLES
Example #1
sqlsrv_field_metadata(3) example
<?php
$serverName = "serverNamesqlexpress";
$connectionInfo = array( "Database"=>"AdventureWorks", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$sql = "SELECT * FROM Table_1";
$stmt = sqlsrv_prepare( $conn, $sql );
foreach( sqlsrv_field_metadata( $stmt ) as $fieldMetadata ) {
foreach( $fieldMetadata as $name => $value) {
echo "$name: $value<br />";
}
echo "<br />";
}
?>
SEE ALSO
sqlsrv_client_info(3).
PHP Documentation Group SQLSRV_FIELD_METADATA(3)