Showing posts with label hii. Show all posts
Showing posts with label hii. Show all posts

Friday, March 30, 2012

How Can I Convert Decimal To Hexadecimal

Hi!!!!!

I'm looking for a SQL FUnction that convert a decimal to Hexadecimal and

Hexadecimal to decimal data.

I know the way to convert for. But not with a SQL Function. certainly I

need to know How to express an Exponential Function.

Thank's.Hi!!!!!

I'm looking for a SQL FUnction that convert a decimal to Hexadecimal and

Hexadecimal to decimal data.

I know the way to convert for. But not with a SQL Function. certainly I

need to know How to express an Exponential Function.

Thank's.
check this...

/* User Defined Function To Convert HexaDecimal Value To Decimal Value
Input: HexaDecimal Value In String Format
Output: Decimal Value
*/
CREATE FUNCTION [dbo].[Fn_HEXCONV] (@.HEXVAL as VARCHAR(25)) RETURNS DECIMAL(20,0)
AS BEGIN
/* Declarations Of Variables Two Decimal Values To Store The Intermdeiate & Final Result,
String Value To Store The Hexadecimal Value During The Process,Two Counter Variables*/
DECLARE @.position int, @.INTVAL INT , @.CMDSTR NVARCHAR( 255 ) ,@.DECVAL DECIMAL(20,0),@.DECVALUE DECIMAL(20,0)
/* Initialising Variables */
SET @.position = 1
SET @.DECVAL=0
WHILE @.position <= DATALENGTH(REVERSE(@.HEXVAL)) /* Looping Through The String Until It Reaches The 0th Position */
BEGIN
/* Store The Decimal Value If the Hexa Value is Between A-F */
SET @.CMDSTR=CASE UPPER(SUBSTRING(REVERSE(@.HEXVAL) ,@.position,1)) WHEN 'A' THEN '10' WHEN 'B' THEN '11' WHEN 'C' THEN '12' WHEN 'D' THEN '13' WHEN 'E' THEN '14' WHEN 'F' THEN '15' ELSE SUBSTRING(REVERSE(@.HEXVAL) ,@.position,1) END
SET @.INTVAL=CAST(@.CMDSTR as INT) /* Casting The String To Integer */
SET @.DECVALUE=@.INTVAL
SET @.DECVAL=@.DECVAL+((@.DECVALUE)*POWER(CAST(16 AS BIGINT),@.position-1))/* Finding The Corresponding Decimal Value & Adding it To The Result */
SET @.position=@.position+1 /* Incrementing The Counter */
End
return CAST(@.DECVAL as Decimal(20,0)) /* Return The Converted Decimal Value Back */
End

Hope it will help you.
Joydeep ;)|||That functionality is built in, you don't need a function for it.DECLARE @.d DECIMAL(4)

SET @.d = 128

SELECT CAST(@.d AS VARBINARY(8)), CAST(0x0400000101000000 AS DECIMAL(4))-PatP

Wednesday, March 28, 2012

How can I combine different rows?

Hi!

I have a table looking like

(username) (account number) (start date) (end date) (product)

wich I can have up to 4 lines for the same client.

I wist to transfert those lines into a new table looking like

(username) (account number) (start date 1) (end date 1) (product 1)
(start date 2) (end date 2) ... (product 4)

How (in SQL) I could do it?>I have a table looking like ..

Please post DDL instead of your personal narrative. If you had done
the talbe properly, i mgiht look like this:

CREATE TABLE AccountHistory
(acct_nbr INTEGER NOT NULL,
product_nbr INTEGER NOT NULL,
product_cnt INTEGER DEFAULT 1 NOT NULL
CHECK(product_cnt BETWEEEN ! AND 4),
PRIMARY KEY (acct_nbr, product_nbr, product_cnt),
user_name VARCHAR(25) NOT NULL,
start_date DATETIME NOT NULL,
end_date DATETIME NOT NULL,
CHECK (start_date < end_date));

I left out the REFERENCES clause you would need and some other
things.

Quote:

Originally Posted by

Quote:

Originally Posted by

>which I can have up to 4 lines [sic] for the same client. <<


Lines appear on a paper form or an input screen; a table has rows.
You need a constraint to enforce this rule.

Quote:

Originally Posted by

Quote:

Originally Posted by

>I wish to transfer those lines into a new table looking like .. <<


You also failed to give any rules for sorting the repeating groups.
But th real question is why are you doing this at all?? That would
violate First Normal Form (1NF). This is not a good way to write
SQL.

Friday, March 23, 2012

How can I call a VB function from SQL Server SP?

Hi
I need to use the VB function "strconv" in my SP.
Is it possible?
Can anyone help?
Best regards
David LauWhy? What's so special about that particular string that converting it can't
be done in T-SQL, yet you decided it should be done on the server?
The sp_OA* procedures let you invoke ActiveX components from SQL, but there
are several downsides to this. The two worst IMHO are: possible negative
impact on server stability, and performance issues.
ML
http://milambda.blogspot.com/|||David L. wrote:

> Hi
> I need to use the VB function "strconv" in my SP.
> Is it possible?
> Can anyone help?
> Best regards
> David Lau
AFAIK all the features of strconv are supported by native TSQL
equivalents. It would therefore be simpler and much more efficient to
use the TSQL version rather than make an external call to VB. Take a
look at the string functions in SQL Server Books Online.
The answer to the question in your subject depends on the version of
SQL Server you are using. In SQL 2000 your options are limited to COM
automation using the sp_OA procs or making a call via an extended proc.
Usually it would be better to utilize client-side code or TSQL.
In 2005 you have the option of putting .NET code directly in a proc.
David Portas
SQL Server MVP
--|||don't do that
"David L." <DavidL@.discussions.microsoft.com> wrote in message
news:A3447E24-AD32-42D0-A834-9C8977D5596C@.microsoft.com...
> Hi
> I need to use the VB function "strconv" in my SP.
> Is it possible?
> Can anyone help?
> Best regards
> David Lau|||Hello David L.,

> I need to use the VB function "strconv" in my SP.
If you're just doing UpperCase/LowerCase, there's the Upper() and Lower()
functions in T-SQL. If your wanting ProperCase and you're using SQL2005,
you can wrap the function with SQLCLR, ala:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Partial Public Class StringConversionFunctions
<Microsoft.SqlServer.Server.SqlFunction()> _
Public Shared Function ProperCase(ByVal Source As SqlString) As SqlString
Return New SqlString(StrConv(Source.Value, VbStrConv.ProperCase))
End Function
End Class
Call it via:
select 'Proper',dbo.ProperCase('ThE QUick BROWN fox jumpEd oVeR thE laZY
DOG')
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/|||Thank you Kent and everyone who has replied this email.
Let's say I would like to do the Narrow for Japanese charactors.
Is there any similar function in TSQL?
Best regards
David
"Kent Tegels" wrote:

> Hello David L.,
>
> If you're just doing UpperCase/LowerCase, there's the Upper() and Lower()
> functions in T-SQL. If your wanting ProperCase and you're using SQL2005,
> you can wrap the function with SQLCLR, ala:
> Imports System
> Imports System.Data
> Imports System.Data.SqlClient
> Imports System.Data.SqlTypes
> Imports Microsoft.SqlServer.Server
> Partial Public Class StringConversionFunctions
> <Microsoft.SqlServer.Server.SqlFunction()> _
> Public Shared Function ProperCase(ByVal Source As SqlString) As SqlStr
ing
> Return New SqlString(StrConv(Source.Value, VbStrConv.ProperCase))
> End Function
> End Class
> Call it via:
> select 'Proper',dbo.ProperCase('ThE QUick BROWN fox jumpEd oVeR thE laZY
> DOG')
>
> Thank you,
> Kent Tegels
> DevelopMentor
> http://staff.develop.com/ktegels/
>
>|||Hello David L.,

> Thank you Kent and everyone who has replied this email.
> Let's say I would like to do the Narrow for Japanese charactors.
> Is there any similar function in TSQL?
Not that I'm immediately aware since it's not really clear to me what Narrow
actually does. Is it something like this?
declare @.m1 nvarchar(50)
set @.m1 = N'? 150 ?'
select cast(@.m1 as varchar(50))
Either way, you should still be able to use the code previously shown with
a different enumeration value.
Domo,
Kentsql

How can i backup sql 2000 using win 2003 backup util

Hi
I have a windows 2003 server running sql. I would like to backup SQL 2000
databases using the built in backup software to a network location.
Could anyone tell me how i do this.
Thanks
Nick
To do this properly, you would have to take the databases offline, or stop
the SQL Server service.
Are you not able to use the built-in-and-highly-effective SQL Server backup
and then take those .bak files to a network location?
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
"Nick" <andync55@.hotmail.com> wrote in message
news:OvQct%23a1FHA.2428@.tk2msftngp13.phx.gbl...
> Hi
> I have a windows 2003 server running sql. I would like to backup SQL 2000
> databases using the built in backup software to a network location.
> Could anyone tell me how i do this.
>
> Thanks
> Nick
>
|||Hi
Thanks for the fast reply. Can i do that by right clicking on each databse
and selecting backup. Is that all i need to do. Is there any other sql
setting i should backup other than just the databases.
Thanks
Nick Comper
"Kevin3NF" <KHill@.NopeIDontNeedNoSPAM3NF-inc.com> wrote in message
news:ehe21Jb1FHA.3660@.TK2MSFTNGP15.phx.gbl...
> To do this properly, you would have to take the databases offline, or stop
> the SQL Server service.
> Are you not able to use the built-in-and-highly-effective SQL Server
> backup and then take those .bak files to a network location?
> --
> Kevin Hill
> President
> 3NF Consulting
> www.3nf-inc.com/NewsGroups.htm
>
> "Nick" <andync55@.hotmail.com> wrote in message
> news:OvQct%23a1FHA.2428@.tk2msftngp13.phx.gbl...
>
|||HowTo: Backup to UNC name using Database Maintenance Wizard
http://support.microsoft.com/?kbid=555128
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"Nick" <andync55@.hotmail.com> wrote in message
news:eLJqeOb1FHA.3720@.TK2MSFTNGP14.phx.gbl...
> Hi
> Thanks for the fast reply. Can i do that by right clicking on each databse
> and selecting backup. Is that all i need to do. Is there any other sql
> setting i should backup other than just the databases.
> Thanks
> --
> Nick Comper
> "Kevin3NF" <KHill@.NopeIDontNeedNoSPAM3NF-inc.com> wrote in message
> news:ehe21Jb1FHA.3660@.TK2MSFTNGP15.phx.gbl...
>
|||Hi
Thanks for the fast reply. Can i do that by right clicking on each databse
and selecting backup. Is that all i need to do. Is there any other sql
setting i should backup other than just the databases.
Thanks
Nick Comper
"Kevin3NF" <KHill@.NopeIDontNeedNoSPAM3NF-inc.com> wrote in message
news:ehe21Jb1FHA.3660@.TK2MSFTNGP15.phx.gbl...
> To do this properly, you would have to take the databases offline, or stop
> the SQL Server service.
> Are you not able to use the built-in-and-highly-effective SQL Server
> backup and then take those .bak files to a network location?
> --
> Kevin Hill
> President
> 3NF Consulting
> www.3nf-inc.com/NewsGroups.htm
>
> "Nick" <andync55@.hotmail.com> wrote in message
> news:OvQct%23a1FHA.2428@.tk2msftngp13.phx.gbl...
>

How can i backup sql 2000 using win 2003 backup util

Hi
I have a windows 2003 server running sql. I would like to backup SQL 2000
databases using the built in backup software to a network location.
Could anyone tell me how i do this.
Thanks
NickTo do this properly, you would have to take the databases offline, or stop
the SQL Server service.
Are you not able to use the built-in-and-highly-effective SQL Server backup
and then take those .bak files to a network location?
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
"Nick" <andync55@.hotmail.com> wrote in message
news:OvQct%23a1FHA.2428@.tk2msftngp13.phx.gbl...
> Hi
> I have a windows 2003 server running sql. I would like to backup SQL 2000
> databases using the built in backup software to a network location.
> Could anyone tell me how i do this.
>
> Thanks
> Nick
>|||Hi
Thanks for the fast reply. Can i do that by right clicking on each databse
and selecting backup. Is that all i need to do. Is there any other sql
setting i should backup other than just the databases.
Thanks
Nick Comper
"Kevin3NF" <KHill@.NopeIDontNeedNoSPAM3NF-inc.com> wrote in message
news:ehe21Jb1FHA.3660@.TK2MSFTNGP15.phx.gbl...
> To do this properly, you would have to take the databases offline, or stop
> the SQL Server service.
> Are you not able to use the built-in-and-highly-effective SQL Server
> backup and then take those .bak files to a network location?
> --
> Kevin Hill
> President
> 3NF Consulting
> www.3nf-inc.com/NewsGroups.htm
>
> "Nick" <andync55@.hotmail.com> wrote in message
> news:OvQct%23a1FHA.2428@.tk2msftngp13.phx.gbl...
>|||HowTo: Backup to UNC name using Database Maintenance Wizard
http://support.microsoft.com/?kbid=555128
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"Nick" <andync55@.hotmail.com> wrote in message
news:eLJqeOb1FHA.3720@.TK2MSFTNGP14.phx.gbl...
> Hi
> Thanks for the fast reply. Can i do that by right clicking on each databse
> and selecting backup. Is that all i need to do. Is there any other sql
> setting i should backup other than just the databases.
> Thanks
> --
> Nick Comper
> "Kevin3NF" <KHill@.NopeIDontNeedNoSPAM3NF-inc.com> wrote in message
> news:ehe21Jb1FHA.3660@.TK2MSFTNGP15.phx.gbl...
>|||Hi
Thanks for the fast reply. Can i do that by right clicking on each databse
and selecting backup. Is that all i need to do. Is there any other sql
setting i should backup other than just the databases.
Thanks
Nick Comper
"Kevin3NF" <KHill@.NopeIDontNeedNoSPAM3NF-inc.com> wrote in message
news:ehe21Jb1FHA.3660@.TK2MSFTNGP15.phx.gbl...
> To do this properly, you would have to take the databases offline, or stop
> the SQL Server service.
> Are you not able to use the built-in-and-highly-effective SQL Server
> backup and then take those .bak files to a network location?
> --
> Kevin Hill
> President
> 3NF Consulting
> www.3nf-inc.com/NewsGroups.htm
>
> "Nick" <andync55@.hotmail.com> wrote in message
> news:OvQct%23a1FHA.2428@.tk2msftngp13.phx.gbl...
>

How can I avoid lots of spaces being added to the end when saving contents of a textbox

Hi

I am using FormView, SQL 2005, VB 2005

When I save the contents of Title and Area entry fields , I have lots of spaces added to the end.

Title and Area are MultiLine Textboxes and database:varchar(100)

I thought I had solved the issue using;

TextBox Title = FormView1.FindControl("TitleTextBox")asTextBox;

TextBox Area = FormView1.FindControl("AreaTextBox")asTextBox;

TitleLenTrim = Title.Text.Trim().ToString();

if (TitleLenTrim.Length > 100)

{

TitleLenTrim = TitleLenTrim.Trim().Substring(0, 99);

}

string AreaLenTrim;

AreaLenTrim = Area.Text.Trim().ToString();

if (AreaLenTrim.Length > 100)

{

AreaLenTrim = AreaLenTrim.Trim().ToString();

}

string insertSQL;

insertSQL ="INSERT INTO Issue(";

insertSQL +="ProjectID, TypeofEntryID, PriorityID ,Title, Area)";

insertSQL +="VALUES ( '";

insertSQL += ProjectID.Text.ToString() +"', '";

insertSQL += EntryTypeID.Text.ToString() +"', '";

insertSQL += PriorityID.Text.ToString() +"', '";

insertSQL += TitleLenTrim.Trim().ToString() +"', '";

insertSQL += AreaLenTrim.Trim().ToString() +"', '";

Is there any other way I could remove spaces?

Thanks in advance.

My guess is that your columns are defined with data typechar instead ofvarchar. SQL Server will pad char columns with spaces.

Also, you should be using Parameters, not concatenating UI-supplied data directly to SQL statements. This is an insecure practice.

|||

Thankstmorton , you were right, I had declared the two columns as char.

Could you please explain more regarding using Parameters, not concatenating UI-supplied data directly to SQL statements?

Thanks in advance

|||

string insertSQL;

insertSQL ="INSERT INTO Issue(";

insertSQL +="ProjectID, TypeofEntryID, PriorityID ,Title, Area)";

insertSQL +="VALUES ( '";

insertSQL += ProjectID.Text.ToString() +"', '";

insertSQL += EntryTypeID.Text.ToString() +"', '";

insertSQL += PriorityID.Text.ToString() +"', '";

insertSQL += TitleLenTrim.Trim().ToString() +"', '";

insertSQL += AreaLenTrim.Trim().ToString() +"', '";

Becomes:

string insertSQL;

insertSQL ="INSERT INTO Issue(ProjectID, TypeofEntryID, PriorityID ,Title, Area) VALUES (@.ProjectID, @.TypeofEntryID, @.PriorityID ,@.Title, @.Area)";

cmdInsert SqlCommand;

cmdInsert=new SqlCommand(insertSQL,conn);

cmdInsert.Parameters.Add("@.ProjectID",SqlDbType.Varchar).Value=ProjectID.Text;

cmdInsert.Parameters.Add("@.EntryTypeID",SqlDbType.Varchar).Value=EntryTypeID.Text;

...

cmdInsert.ExecuteNonQuery;

(Sorry if my C# syntax isn't exact)

|||

Thanks Motley, It works fine until I try to insert a date.

Previous code was

insertSQL +="convert(datetime,'" +DateTime.Now.ToString("dd/MM/yy") +"',3), '";

I tried the code below but the record doesn't save?

Thanks in advance

string date = DateTime.Now.ToString("dd/MM/yy");

insertSQL = "INSERT INTO WorkFlow(IssueID, TaskID, TaskDone, Date ,StaffID) VALUES (@.IDIssue, @.IDTask, @.TaskDone, convert(DateTime,@.Date,3),@.IDStaff)";

cmdInsert.Parameters.Add("IDIssue", SqlDbType.Int).Value = IDIssue.ToString();

cmdInsert.Parameters.Add("IDTask",SqlDbType.Int).Value = IDTask.Text;

cmdInsert.Parameters.Add("TaskDone",SqlDbType.VarChar).Value = TaskDoneTxtbox.Text;

cmdInsert.Parameters.Add("Date",SqlDbType.DateTime).Value = date;

cmdInsert.Parameters.Add("IDStaff",SqlDbType.Int).Value = IDStaff.Text;

Wednesday, March 21, 2012

How can I alter an int column to IDENTITY

Hi!
I have to copy complete table with auto increment column.
I create integer column, copy the data into it and want to alter it to
integer IDENTITY(1,1) PRIMARY KEY.
This SQL command cause an error : ALTER TABLE TableName ALTER COLUMN
ColumnName int IDENTITY(1,1) in Query Analyzer.
In SQL-DMO the identity property of the column is read only after the
creation.
This SQL command is good : SET IDENTITY_INSERT TableName ON
But I can insert rows only from SQL command not from an OLEDB recordset.
Exists the way to alter a column to IDENTITY not from Enterprise Manager?
I will be glad of any answer.
Regards,
Imre AmentNo, you can't alter a column to give it the IDENTITY property. You can drop
and recreate the column (if your table is empty). In the scenario you
describe, you can create the table _with_ the integer column with IDENTITY,
then SET IDENTITY_INSERT TableName ON, copy in the data, and then set
IDENTITY_INSERT off again.
Jacco Schalkwijk
SQL Server MVP
"Imre Ament" <ImreAment@.discussions.microsoft.com> wrote in message
news:77B40A32-3DF1-4543-8392-9D199EC0FCBA@.microsoft.com...
> Hi!
> I have to copy complete table with auto increment column.
> I create integer column, copy the data into it and want to alter it to
> integer IDENTITY(1,1) PRIMARY KEY.
> This SQL command cause an error : ALTER TABLE TableName ALTER COLUMN
> ColumnName int IDENTITY(1,1) in Query Analyzer.
> In SQL-DMO the identity property of the column is read only after the
> creation.
> This SQL command is good : SET IDENTITY_INSERT TableName ON
> But I can insert rows only from SQL command not from an OLEDB recordset.
> Exists the way to alter a column to IDENTITY not from Enterprise Manager?
> I will be glad of any answer.
> Regards,
> Imre Ament

How can I alter an int column to IDENTITY

Hi!
I have to copy complete table with auto increment column.
I create integer column, copy the data into it and want to alter it to
integer IDENTITY(1,1) PRIMARY KEY.
This SQL command cause an error : ALTER TABLE TableName ALTER COLUMN
ColumnName int IDENTITY(1,1) in Query Analyzer.
In SQL-DMO the identity property of the column is read only after the
creation.
This SQL command is good : SET IDENTITY_INSERT TableName ON
But I can insert rows only from SQL command not from an OLEDB recordset.
Exists the way to alter a column to IDENTITY not from Enterprise Manager?
I will be glad of any answer.
Regards,
Imre Ament
No, you can't alter a column to give it the IDENTITY property. You can drop
and recreate the column (if your table is empty). In the scenario you
describe, you can create the table _with_ the integer column with IDENTITY,
then SET IDENTITY_INSERT TableName ON, copy in the data, and then set
IDENTITY_INSERT off again.
Jacco Schalkwijk
SQL Server MVP
"Imre Ament" <ImreAment@.discussions.microsoft.com> wrote in message
news:77B40A32-3DF1-4543-8392-9D199EC0FCBA@.microsoft.com...
> Hi!
> I have to copy complete table with auto increment column.
> I create integer column, copy the data into it and want to alter it to
> integer IDENTITY(1,1) PRIMARY KEY.
> This SQL command cause an error : ALTER TABLE TableName ALTER COLUMN
> ColumnName int IDENTITY(1,1) in Query Analyzer.
> In SQL-DMO the identity property of the column is read only after the
> creation.
> This SQL command is good : SET IDENTITY_INSERT TableName ON
> But I can insert rows only from SQL command not from an OLEDB recordset.
> Exists the way to alter a column to IDENTITY not from Enterprise Manager?
> I will be glad of any answer.
> Regards,
> Imre Ament