Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, March 23, 2012

Saving dates to SQL

I am fairly new to SQL programming, and have a problem with dates.

In my SQL text in vb.net i have this set to eg "04/09/06 00.00.01" executing that

sql command works fine, but when i go to read the data back its shows as

09/04/06. If the dates is something like 25/09/06 it fails because i assume SQL

read this as day 9 of month 25!.

I have UK dates in control panel, how can i ensure SQL supports UK style dates

The field type is datetime, i am using the executenonquery command after setting the commandtext to the sql syntax.

Many Thanks for your help in advance

Chris Anderson

First of all, for storage reasons, SQL Server doesn′t matter which language the user is using. The appropiate display format is determined when the user is querying the data. But SQL Server will only pass back the date (if not other queried) as a native datetime leaving it to the client to change back the date a the user needs it. How do you store the date ? Is it a datetime or a string ? If its a datetime it is not stored as the 25th month of the year, because would have led to a onversion error at insert time notbeing in the valid range for datetimes. You mighthave a deeper look ino the format of your textbox in the frontend.

HTH; Jens K. Suessmeyer.

http://www.sqlserver2005.de
|||

Many thanks for your reply. It is a datetime variable but i have solved the problem having seen another post.

I use the YYYYMMDD 00:00:00 format, and have a function to convert my date into this format before i shoot it off to SQL Server.

Worked perfectly.

Thanks again

sql

Saving dates to SQL

I am fairly new to SQL programming, and have a problem with dates.

In my SQL text in vb.net i have this set to eg "04/09/06 00.00.01" executing that

sql command works fine, but when i go to read the data back its shows as

09/04/06. If the dates is something like 25/09/06 it fails because i assume SQL

read this as day 9 of month 25!.

I have UK dates in control panel, how can i ensure SQL supports UK style dates

The field type is datetime, i am using the executenonquery command after setting the commandtext to the sql syntax.

Many Thanks for your help in advance

Chris Anderson

First of all, for storage reasons, SQL Server doesn′t matter which language the user is using. The appropiate display format is determined when the user is querying the data. But SQL Server will only pass back the date (if not other queried) as a native datetime leaving it to the client to change back the date a the user needs it. How do you store the date ? Is it a datetime or a string ? If its a datetime it is not stored as the 25th month of the year, because would have led to a onversion error at insert time notbeing in the valid range for datetimes. You mighthave a deeper look ino the format of your textbox in the frontend.

HTH; Jens K. Suessmeyer.

http://www.sqlserver2005.de|||

Many thanks for your reply. It is a datetime variable but i have solved the problem having seen another post.

I use the YYYYMMDD 00:00:00 format, and have a function to convert my date into this format before i shoot it off to SQL Server.

Worked perfectly.

Thanks again

Saving changes

Hi, all.

This might be a silly question... but I am very new to programming in
SQL so please bear with me :)

So. I'm using MS SQL Server 2005 Management Studio Express. I have a
table that was created via an existing .sql file. Included were a
bunch of stored procedures. I went in to re-format these procedures.
(They were written in haste by another programmer. It is my task to go
back and improve their readabilities.) However, I am having difficulty
figuring out how to save the changes to these stored procedures. Thus
far, I have been individually saving each stored procedure in its
own .sql file. This is obviously not the way to go... but it's a
temporary solution (so as not to lose the changes I have made to
dozens of procedures).

Can someone please explain to me how I commit these changes to the
database?

Thanks,
AllieAllie (fakeprogress@.gmail.com) writes:

Quote:

Originally Posted by

So. I'm using MS SQL Server 2005 Management Studio Express. I have a
table that was created via an existing .sql file. Included were a
bunch of stored procedures. I went in to re-format these procedures.
(They were written in haste by another programmer. It is my task to go
back and improve their readabilities.) However, I am having difficulty
figuring out how to save the changes to these stored procedures. Thus
far, I have been individually saving each stored procedure in its
own .sql file. This is obviously not the way to go... but it's a
temporary solution (so as not to lose the changes I have made to
dozens of procedures).


I think that is exactly the way to go. You should also put the files under
source control.

Quote:

Originally Posted by

Can someone please explain to me how I commit these changes to the
database?


But that's not saving. You save a file to the file system, and as I said,
you also put it under version control.

To change the database what's in the database is more akin to a compilation.
To make this easy to handle, I suggest that you have this in your files:

IF object_id('my_sp') IS NULL
EXEC ('CREATE PROCEDURE my_sp AS SELECT 1')
go
ALTER PROCEDURE my_sp -- real code follows here

Then it doesn't matter when you run the file, whether the procedure
exists or not.

And to run the file from Mgmt Studio, you can clich the green arrow,
or press CTRL/E or F5.

When you need to load several files, this is more convenient to do
from a BAT file and use SQLCMD instaead.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Tuesday, February 21, 2012

Sample's reference

Forgive me for my programming ignorance, but how to i find the microsoft.sqlserverce.samples.accesssync.editdata reference?

Thanks

Do you mean this one?:

C:\Program Files\Microsoft SQL Server Compact Edition\v3.1\sync\Access\Sample

Sample for ADOMD.NET Server Programming

Hi all,

Can I get Samples for ADOMD.Net Server Programming

Thanks,

Check out this MSDN site http://msdn2.microsoft.com/en-us/library/ms123483.aspx I couldn't find the sample codes I created last year.