Showing posts with label character. Show all posts
Showing posts with label character. Show all posts

Tuesday, March 27, 2012

Default Field Value for DateTime & SmallDateTime

In SQL Server 2000 / Asp.Net I am trying to use default values for all fields; hoping to eliminate nulls.

For number and character fields, the default is pretty obvious, but is there any empty value for a date field? I think a null there might be better than putting in a bogus date, at least it can be tested for.

Are there any more developend ideas on this question?

Many thanks
Mike ThomasHi, Mike.
The choise depends directly on the problem U r solving. Sometimes GETDATE() helps... just analize Ur task and make a corresponding conclusion: what value is permitable as a default one in the definite case...

Alex.sql

Friday, March 9, 2012

Decimal to Hex formatting

I have a specific SQL Server coding problem.
I have an 8 character field that is an integer.
eg: 16776976
In hex this is FFFF10
This represents the Red, Green and Blue hex values for a colour, in
reverse order:
ie. 10 is red, FF is green, FF is blue
I need my SQL Server stored procedure to be able to get from the 8
character field to the red, green and blue codes. How do I get 16776976
into FFFF10 so I can then simply substring the appropriate values?
MarkHi
SELECT CAST(16776976 AS VARBINARY(10))
"stainless" <Mark.Wingfield@.gmail.com> wrote in message
news:1123583639.609068.92820@.g49g2000cwa.googlegroups.com...
>I have a specific SQL Server coding problem.
> I have an 8 character field that is an integer.
> eg: 16776976
> In hex this is FFFF10
> This represents the Red, Green and Blue hex values for a colour, in
> reverse order:
> ie. 10 is red, FF is green, FF is blue
> I need my SQL Server stored procedure to be able to get from the 8
> character field to the red, green and blue codes. How do I get 16776976
> into FFFF10 so I can then simply substring the appropriate values?
> Mark
>|||This will return 16776976 as 0x00FFFF10 in a varbinary format. However,
as this is not a text field, it is not a simple substring command to
get FF, FF and 10 out of this string. How can I extract these bytes
from this varbinary field so I actually have FF, FF and 10 as actual
text?
(I may also have to convert these into decimal integers but that is in
another step e.g. FF is 255)
Cheers
Mark|||Mark, perhaps this can help:
CREATE FUNCTION dbo.fn_dectobase(@.val AS bigint, @.base AS int)
RETURNS varchar(63)
AS
BEGIN
DECLARE @.r AS varchar(63), @.alldigits AS varchar(36);
SET @.alldigits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
SET @.r = '';
WHILE @.val > 0
BEGIN
SET @.r = SUBSTRING(@.alldigits, @.val % @.base + 1, 1) + @.r;
SET @.val = @.val / @.base;
END
RETURN @.r;
END
GO
SELECT dbo.fn_dectobase(16776976, 16);
Output: FFFF10
BG, SQL Server MVP
www.SolidQualityLearning.com
"stainless" <Mark.Wingfield@.gmail.com> wrote in message
news:1123583639.609068.92820@.g49g2000cwa.googlegroups.com...
>I have a specific SQL Server coding problem.
> I have an 8 character field that is an integer.
> eg: 16776976
> In hex this is FFFF10
> This represents the Red, Green and Blue hex values for a colour, in
> reverse order:
> ie. 10 is red, FF is green, FF is blue
> I need my SQL Server stored procedure to be able to get from the 8
> character field to the red, green and blue codes. How do I get 16776976
> into FFFF10 so I can then simply substring the appropriate values?
> Mark
>|||On 9 Aug 2005 03:33:59 -0700, stainless wrote:

>I have a specific SQL Server coding problem.
>I have an 8 character field that is an integer.
>eg: 16776976
>In hex this is FFFF10
>This represents the Red, Green and Blue hex values for a colour, in
>reverse order:
>ie. 10 is red, FF is green, FF is blue
>I need my SQL Server stored procedure to be able to get from the 8
>character field to the red, green and blue codes. How do I get 16776976
>into FFFF10 so I can then simply substring the appropriate values?
Hi Mark,
The following will give you the integer values for R, G and B:
declare @.num int
set @.num = 16776976
select @.num / 65536 AS R, @.num % 65536 / 256 AS G, @.num % 256 AS B
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Friday, February 17, 2012

Debug stored procedure in query analyzer

Trying to use Debug feature in query analyzer -- on some systems I get the
message
[Microsoft][ODBC SQL Server Driver]Invalid character value for cast
specification
There's nothing wrong with the stored procedure. If I have this problem, it
happens with all stored procedures except those that have no parameters. If
there are no parameters, the message doesn't show, but debug still doesn't
work properly.
Carole
You may have to specify date parameter values in a specific format. For
example, see:
http://groups-beta.google.com/group/...f1164645c4a4f9
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"CDuttlinger" <h2oPower@.newsgroup.nospam> wrote in message
news:6E2C1A97-A747-4BC6-979B-CE090C67B6A4@.microsoft.com...
> Trying to use Debug feature in query analyzer -- on some systems I get the
> message
> [Microsoft][ODBC SQL Server Driver]Invalid character value for cast
> specification
> There's nothing wrong with the stored procedure. If I have this problem,
> it
> happens with all stored procedures except those that have no parameters.
> If
> there are no parameters, the message doesn't show, but debug still doesn't
> work properly.
> --
> Carole
|||That doesn't explain why debug works on some computers and not others, with
the same stored procedures.
Carole
"Narayana Vyas Kondreddi" wrote:

> You may have to specify date parameter values in a specific format. For
> example, see:
> http://groups-beta.google.com/group/...f1164645c4a4f9
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> "CDuttlinger" <h2oPower@.newsgroup.nospam> wrote in message
> news:6E2C1A97-A747-4BC6-979B-CE090C67B6A4@.microsoft.com...
>
>
|||Perhaps the debugger does something to the input, where what it does is dependent on Regional
Settings in windows?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"CDuttlinger" <h2oPower@.newsgroup.nospam> wrote in message
news:ED00A9CE-A366-4F9D-B60A-7DE5F090302E@.microsoft.com...[vbcol=seagreen]
> That doesn't explain why debug works on some computers and not others, with
> the same stored procedures.
> --
> Carole
>
> "Narayana Vyas Kondreddi" wrote: