473,411 Members | 1,982 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,411 software developers and data experts.

date format default for xp_cmdshell

2
I have SQL statements that I run in Query Analyzer with character date values as parameters which work fine - QA recognises (for example) 20/12/2006 as dd/mm/yyyy. My QA is v 8.00.2039.

But when I run those same statements in xp_cmdshell, the implicit char-to-date conversion reads that as mm/dd/yyyy and of course fails.

I've tried both isql and osql in my syntax (see below) but always get the same (wrong) results. Obviously xp_cmdshell is reading a date setting default somewhere different than QA is. Where do I go to modify that default so all character date fields are recognised as dd/mm/yyyy?

Expand|Select|Wrap|Line Numbers
  1. exec master..xp_cmdshell 'isql -E dbname -Q "exec dbname..storedproc" -o output'
  2. exec master..xp_cmdshell 'osql -E dbname -Q "exec dbname..storedproc" -o output'
  3.  
Thanks, Sharon.
Dec 21 '06 #1
4 4037
iburyak
1,017 Expert 512MB
Convert date to character before the output.
Use desired style of convert function. See example below:

[PHP]select convert(varchar, getdate(), 103)[/PHP]
Dec 22 '06 #2
smatyk
2
Hi - erm, I probably didn't explain well enough. I do know how to use convert and cast for different date formats - and anyway, char(10) format 103 is exactly my problem. That's dd/mm/yyyy but xp_cmdshell is reading that as mm/dd/yyyy and causing errors.

I have vb.net code that produces a page where the user can tick a box to select a report to run, and some reports have date parameters. So, the asp code picks up the characters typed for the date value - in the UK it means the user wants to type 20/12/2006 for example - and puts that into a variable. A stored procedure is run which places that variable into my data-select code; for example:
Expand|Select|Wrap|Line Numbers
  1. select * from table where trandate=@aspdate
When the stored procedure is run in QA I can feed in 20/12/2006 and the statement works fine. When the stored procedure is run via xp_cmdshell (using isql or osql syntax) then those same characters are being read as month then day and it errors.

I have a workaround in that if the user types 20-dec-2006 then I can use that value in my syntax as:
Expand|Select|Wrap|Line Numbers
  1. where trandate=cast(@aspdate as datetime)
and it all works again.

My issue is, there is some fundamental default US date format somewhere in our system. It ain't in QA, and the box on which SQL Server is installed appears to be fine with all UK regional settings. So, what is xp_cmdshell looking at, for it to do implicit conversions from aa/bb/cccc characters into an assumed mm/dd/yyyy date format?
Thanks, Sharon.
Jan 2 '07 #3
navamnk
15
use this statement in your SP

SET DATEFORMAT mdy
Jan 3 '07 #4
iburyak
1,017 Expert 512MB
You can't do select * this is a problem you have to list all columns in your select statement and convert date columns to text field with desired format this way it will never convert it back because it will be treated as text .

[PHP]
select column1, column2, column3, convert(varchar(30), trandate, 103) as trandate, -- continue list of other columns in a table here
from table where trandate=cast(@aspdate as datetime)[/PHP]
Jan 3 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Yvonne | last post by:
Would like to implement Blat on SQL Server 2000. I'm looking for example syntax for setting up BLAT with xp_cmdshell. TIA
15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
6
by: Willie wjb | last post by:
Hi, i have a client program that sends a filter expression to the server PC. On that server PC this filter is put over a datatable and the result is send back. the server can be located on a...
3
by: Marauderz | last post by:
Hello guys, got a little question regarding the regional language settings . Anyway I got a Windows 2003 Server machine that was installed with the date format "dd/MM/yyyy" and location still...
12
by: Rob T | last post by:
I'm storing a date/time into a SQL table of type datetime. I need it to be precise so the value is stored to the 1000th of a second. ie "insert into myTable mydate values ('08/05/2005...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
1
by: Tom | last post by:
I need to modify the default behavior of Date.ToString() on all pages of my ASP.Net (2.0) site. I don't need to localize my app (it's an intranet-only site), but I need to enforce a specific...
2
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.