Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Stored Procedure from C++ with DateTime as Parameter

Status
Not open for further replies.

negronr

Programmer
Aug 19, 2002
5
US
Hello -

I need to call a stored procedure using VC++ 6 that has a datetime parameter. If the stored procedure is expecting a datetime as a parameter how will I send a datetime stamp as parameter ?

For example: Procedure A(@datetime);
Calling Procedure A: A('2002-02-02 00:00:00'); ?????

Thanks
 
You don't mention what type of library you're using to connect to Sybase and this might conceivable make a difference (for instance if you're using a Prepared Statement type call it might work differently than a DbLib or CTLib call--I can't say for sure because it depends on how the particular library you're using would handle a datetime/parameter substitution). If you're using CTLib or DbLib, and no prepared statement, the following explanation should hold:

The general rule is that when your program is submitting a query to the DB, you are passing text to the server which is in the form of SQL commands--but it is text. Underneath any higher-level calls you or your colleagues have implemented, what's happening is that a command buffer is being stuffed with the text and then an execute command is passed to the database library to send the command buffer contents to the server. But, what gets sent is text. Therefore, to call a stored procedure which takes a datetime parameter from a program, you'd format the datetime value just as you would when you invoke the command from an interactive SQL session. E.g.:

create proc takeDateTime (@theTime datetime)
as
select @theTime
go

execute takeDateTime '2002.01.01'
go

So, your program needs to generate that string of characters and pass it to the SQL command buffer and then execute the command.

Depending upon what kind of format you have for the datetime parameter your program is trying to pass, you may need to do an internal conversion within the program to create an appropriate string representation of the datetime value.

HTH,

John J M Craig
Alpha-G Consulting, LLC
nsjmcraig@netscape.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top