473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I use pass data to/from stored procedure

Hello,
I read an article on how to use Yahoos API to GeoCode addresses. Based
on the article I created a stored procedure that is used as follows:
SPGeocode '2121 15st north' ,'arlington' ,'va' ,'warehouse-test'
Returns:
Latitude Longitude GeoCodedCity GeoCodedState GeoCodedCountry
Precision Warning
----------- ---------- ------------- ------------- ---------------
--------------- --------
38.889538 -77.08461 ARLINGTON VA US
Precision Good No Error

It returns Latitude and Longitude and other information. Works great.
In conjunction with Haversine formula, I can compute the distance
between two locations if I know the Lat and Long of the two points.
This can start to answer questions like "How many students do we have
within a 10 mile radius of Location X?"
(Marketing should go nuts over this :)

My question is how can i use my data from a table and pass it to the
SPGeocode via a select statement?
The table I would use is:

CREATE TABLE "dbo"."D_BI_Student"
(
"STUDENT_ADDRESS1" VARCHAR(50) NULL,
"STUDENT_ADDRESS2" VARCHAR(50) NULL,
"STUDENT_CITY" VARCHAR(50) NULL,
"STUDENT_STATE" VARCHAR(10) NULL,
"STUDENT_ZIP" VARCHAR(10) NULL
)
;
This is so new to me, I am not even sure what to search.
TIA
Rob

May 2 '06 #1
4 3366
rcamarda (ro*****@hotmail.com) writes:
My question is how can i use my data from a table and pass it to the
SPGeocode via a select statement?
The table I would use is:

CREATE TABLE "dbo"."D_BI_Student"
(
"STUDENT_ADDRESS1" VARCHAR(50) NULL,
"STUDENT_ADDRESS2" VARCHAR(50) NULL,
"STUDENT_CITY" VARCHAR(50) NULL,
"STUDENT_STATE" VARCHAR(10) NULL,
"STUDENT_ZIP" VARCHAR(10) NULL
)
;
This is so new to me, I am not even sure what to search.


If you want to call that procedure for every student in the table, you
would have to set up a cursor over the table and call the proceduire
for each row.

Of course, if it's possible to rewrite that procedure to work on
the entire table directly that's better, but since you seems to be
calling an external API (from an SP???) this may be difficult.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
May 2 '06 #2
Thanks Erland.

For now, I'll try the cursor and one at a time, till I get better
aquanted with the process. I would guess that Yahoo would frown on
batch API calls (they have a 24 hour limit of 50,000 records).
This is what I have so far:

declare @c1 float, @c2 float, @c3 varchar(50), @c4 varchar(50), @state
varchar(10), @zip varchar(10), @country varchar(20)
declare @precision varchar(50), @warning varchar(50)
declare @address1 varchar(50), @city varchar(50)
declare @appid varchar(20)

set @appid = 'warehouse-test'

declare cur cursor fast_forward
for select top 10 student_address1, student_city, student_state,
'warehouse-test'
from student

open cur
fetch next from cur into @address1, @city, @state, @appid
while @@fetch_status = 0
begin
exec SPGeocode @address1, @city, @state, 'warehouse-test'
fetch next from cur into @c1, @c2, @c3, @c4, @state, @zip,
@country, @precision, @warning
end
close cur
deallocate cur

When I execute, I get one row returned, then an error:

Msg 16924, Level 16, State 1, Line 17
Cursorfetch: The number of variables declared in the INTO list must
match that of selected columns.
My confusion is that I need 4 parameters for the procedure, but it
returns more columns.
Do I need to pad the columns, simular to have same number columns when
using a UNION with selects?
TIA
Rob

May 3 '06 #3
Update:
this is returning rows, but its like 10 separeate selects. I need to
get this into a table

declare @c1 float, @c2 float, @c3 varchar(50), @c4 varchar(50), @state
varchar(10), @zip varchar(10), @country varchar(20)
declare @precision varchar(50), @warning varchar(50)
declare @address1 varchar(50), @city varchar(50)
declare @appid varchar(20)
declare @char1 varchar(20), @char2 varchar(20), @char3 varchar(20),
@char4 varchar(20)

set @appid = 'warehouse-test'

declare cur cursor fast_forward
for select top 10 student_address1, student_city, student_state,
'warehouse-test'
from student

open cur
fetch next from cur into @address1, @city, @state, @appid
while @@fetch_status = 0
begin
exec SPGeocode @address1, @city, @state, 'warehouse-test'
fetch next from cur into @address1, @city, @state, @appid
end
close cur
deallocate cur

May 3 '06 #4
rcamarda (ro*****@hotmail.com) writes:
this is returning rows, but its like 10 separeate selects. I need to
get this into a table


Have a look at http://www.sommarskog.se/share_data.html for suggestions.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
May 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access...
0
by: Chan | last post by:
Hi, I am trying to send set of rows from my c# web service to Oracle stored procedure. I think I can get this done using OpenXML in SQL Server. How to implement this in Oracle Stored...
2
by: djharrison | last post by:
Greetings, I was wondering if anyone could help me with a project involving MS Acces as a front-end to an SQL Server 2000 database. I am running a program that currently populates the Access...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
0
by: Chan | last post by:
Hi, I am trying to send set of rows from my c# web service to Oracle stored procedure. I think I can get this done using OpenXML in SQL Server. How to implement this in Oracle Stored...
6
by: Woody Splawn | last post by:
I am using SQL Server 2000 as a back-end to a VS.net Client/Server app. In a certain report I use a view as part of the query spec. For the view, at present, I am querying for all the records in...
1
by: deepdata | last post by:
Hi, I am trying to fetch data from db2 (express version) database by calling stored procedure. I have tried to use both cursor and for loop but still i am getting error. --======Start...
3
by: Joseph Lu | last post by:
Hi, all I have a stored procedure created in SQL Server like the following lines. // stored proceudre code starts here CREATE PROCEDURE sp_insertdata @strdata varchar(250) , @rsult BIT...
3
by: Assimalyst | last post by:
Hi, I have two methods. In one i would like to create a string from a stored procedure to pass to the second which populates a datagrid. private void method() { string sqlString =...
0
by: Satishkeshetty | last post by:
Hi Experts, Could you please help me in the below query? Please help in the below situation, how can create the stored Procedure. I need to create a stored procedure and need to pass date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.