473,795 Members | 3,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find the maximum possible value of a given datatype

Does anyone know of a built-in function to return the maximum possible
value of a given datatype? I have to return the biggest value for a
smalldatetime or datetime in a view if the field is null, but can't
find such a function. The closest I've come is:

select datalength(cast (getdate() as smalldatetime))

....but that only return the number of bytes, not the value itself,
which is '6-6-2079 11:59'

I know I could create my own lookup table and function, but I was
hoping that Transact-SQL would have a built-in solution

--John Hunter

Jun 27 '07 #1
3 10911
>One alternative is to write your own function that encapsulates the
>hardcode. Pass the table and column names, query the system tables
for the type and related information such as max length of a varchar,
and then return it. Clumsy, no doubt.
My apologies, it is nowhere near as simple as I described as, at a
minimum, one function for each datatype group (dates, character
strings, etc) would be required.

Roy Harvey
Beacon Falls, CT
Jun 27 '07 #2
js******@waikat o.ac.nz wrote:
Does anyone know of a built-in function to return the maximum possible
value of a given datatype? I have to return the biggest value for a
smalldatetime or datetime in a view if the field is null,
If you (and the recipient of this return value, if it isn't another
piece of T-SQL) can wrap your head around ternary logic, then you
can use the null value as is:

where not (some_date end_date)

Or, depending on the expected longevity of the system, you can (a)
hard-code June 6, 2079 (max smalldatetime) or (b) avoid smalldatetime
and hard-code December 31, 9999 (max datetime). I would personally
go with (b), as I can't imagine actually designing a system that had
a good reason to use smalldatetime for anything.
Jun 27 '07 #3
No there isn't.

But there are solutions. You can read more at
http://groups.google.nl/group/micros...43f4aea485c6d1
(url may wrap)

HTH,
Gert-Jan
"js******@waika to.ac.nz" wrote:
>
Does anyone know of a built-in function to return the maximum possible
value of a given datatype? I have to return the biggest value for a
smalldatetime or datetime in a view if the field is null, but can't
find such a function. The closest I've come is:

select datalength(cast (getdate() as smalldatetime))

...but that only return the number of bytes, not the value itself,
which is '6-6-2079 11:59'

I know I could create my own lookup table and function, but I was
hoping that Transact-SQL would have a built-in solution

--John Hunter
Jun 27 '07 #4

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

Similar topics

5
1695
by: cai_rongxi | last post by:
Anyone has the solution to the question "Given an array a with value 1...N, find a repeted value" in C code? Thanks a lot
7
6247
by: mp | last post by:
No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters. Source Error:
3
8839
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I don't think I made any changes to either page other than changing the user control that creates the header). Server Error in '/myApp' Application. ---------------------------------------------------------------------------- ----
44
1504
by: MadCrazyNewbie | last post by:
Hey Group, I keep getting a error saying "No Value Given For One Or More Parameters". Unfortunatly I don`t know where this error is coming from:(. Can I run through my code line by line, so I can see which line is faulting? Regards MCN
2
2630
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying to update a record, I get a "No value given for one or more parameters." error message. I use a Select with parameters and an Update with parameters. The select works fine. I thought I've tried everything (evidently not) to get this working. ...
30
5257
by: =?Utf-8?B?VGhvbWFzVDIy?= | last post by:
Hello, I have an array that holds 4 values ( they contain random numbers). I would like to find the lowest value (if there is a tie i would like to find one of the tie.) then remove that value. I am new to Programming and C#. Thanks for any help you can provide Thomas
0
4610
by: AxleWacl | last post by:
Hi, The below error is what I am receiving. The code im using is below the error, for the life of me, I can not see where any parameter is missing..... Server Error in '/FleetcubeNews' Application. -------------------------------------------------------------------------------- No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please...
7
7002
by: laredotornado | last post by:
Hi, I'm using PHP 5 with MySql 5. I have a MySQL InnoDB table with a column of type INTEGER UNSIGNED. Is there a constant in PHP to insert the maximum value possible into the column? The underlying OS is Red Hat Linux, but I'm not sure about the version. Any help you can provide is appreciated, - Dave
1
6464
by: AlsonToh | last post by:
No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters. Source Error: An unhandled exception was generated during the execution of the...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9043
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.