Monday, March 26, 2012
Is it possible to get the max length of a TEXT field?
I can do a select max(len(rtrim(convert(varchar(8000)))) on the field but I'm not able to do for more than 8000 and you can't manipulate TEXT datay type.
Any ideas?
Thanks!SELECT DATALENGTH(Col1) FROM myTable99
Wednesday, March 21, 2012
Is it possible to create CLR function call legacy C++ models?
function. However, too much compiler error. Is it possible to build a CLR
function and call/link.. the legacy C++ code?examnotes <nick@.discussions.microsoft.com> wrote in
news:DA2E1EC7-EFDB-4111-B3A9-0314A8FAA394@.microsoft.com:
> I tried to convert an legacy C++ program to managed C++ and build a
> CLR function. However, too much compiler error. Is it possible to
> build a CLR function and call/link.. the legacy C++ code?
>
As (I believe) I replied earlier to you, you need to either access the C++
object through P/Invoke or COM Interop. In your case it sounds like
P/Invoke is the most likely way of getting to the code, i.e. your C++
object is not a COM component.
Niels
****************************************
**********
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb at develop dot com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
****************************************
**********|||Thanks. Sorry for repost.
One thing I want to know is,
It sounds CLR function required /clr:safe, can safe code still do platform
invoke?
"Niels Berglund" wrote:
> examnotes <nick@.discussions.microsoft.com> wrote in
> news:DA2E1EC7-EFDB-4111-B3A9-0314A8FAA394@.microsoft.com:
>
> As (I believe) I replied earlier to you, you need to either access the C++
> object through P/Invoke or COM Interop. In your case it sounds like
> P/Invoke is the most likely way of getting to the code, i.e. your C++
> object is not a COM component.
> Niels
>
> --
> ****************************************
**********
> * Niels Berglund
> * http://staff.develop.com/nielsb
> * nielsb at develop dot com
> * "A First Look at SQL Server 2005 for Developers"
> * http://www.awprofessional.com/title/0321180593
> ****************************************
**********
>|||examnotes <nick@.discussions.microsoft.com> wrote in
news:7205E76E-7B6D-4572-B5EF-B01A7E312456@.microsoft.com:
> It sounds CLR function required /clr:safe, can safe code still do
> platform invoke?
>
In order to do P/Invoke you need to create your assembly in SQL as unsafe.
Niels
****************************************
**********
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb at develop dot com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
****************************************
**********|||"Niels Berglund" <nielsb@.nospam.develop.com> wrote in message
news:Xns97AADD8FEE8DEnielsbdevelopcom@.20
7.46.248.16...
> examnotes <nick@.discussions.microsoft.com> wrote in
> news:7205E76E-7B6D-4572-B5EF-B01A7E312456@.microsoft.com:
>
> In order to do P/Invoke you need to create your assembly in SQL as unsafe.
>
Running unsafe code in the database is, well, unsafe. Your legacy C++ code
can crash SQL Server. So you should check with whoever owns the production
SQL Server you will target and make sure they are OK with you running this
code inside the database.
David|||Organization: DevelopMentor
Message-ID: <Xns97AB12F509BB6nielsbdevelopcom@.207.46.248.16>
User-Agent: Xnews/2006.03.14
Newsgroups: microsoft.public.sqlserver.programming
Date: Wed, 19 Apr 2006 17:51:47 -0700
NNTP-Posting-Host: 69.177.80.118.adsl.snet.net 69.177.80.118
Path: TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
Lines: 1
Xref: TK2MSFTNGP01.phx.gbl microsoft.public.sqlserver.programming:597705
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
news:ufkHThAZGHA.4836@.TK2MSFTNGP05.phx.gbl:
> Running unsafe code in the database is, well, unsafe. Your legacy C++
> code can crash SQL Server. So you should check with whoever owns the
> production SQL Server you will target and make sure they are OK with
> you running this code inside the database.
>
Well, to put things into perspective; running unsafe CLR code inside the
database is inherently safer than running extended procs. But yes, you are
right in that the code should be checked so it won't cause damage.
Niels
****************************************
**********
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb at develop dot com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
****************************************
**********|||"Niels Berglund" <nielsb@.nospam.develop.com> wrote in message
news:Xns97AB12F509BB6nielsbdevelopcom@.20
7.46.248.16...
> "David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
> news:ufkHThAZGHA.4836@.TK2MSFTNGP05.phx.gbl:
>
> Well, to put things into perspective; running unsafe CLR code inside the
> database is inherently safer than running extended procs. But yes, you are
> right in that the code should be checked so it won't cause damage.
>
Unsafe managed code is one thing. P/Invoke to legacy C++ code is another.
David|||well, clr function call legacy dll has too much trouble,
- need to set security to let the user has permission
- or create public key and use it to sign the assembly
- parameter passing...
make the solution less favorite.
i will go to bcp to text file, processing and bulk insert back
"David Browne" wrote:
> "Niels Berglund" <nielsb@.nospam.develop.com> wrote in message
> news:Xns97AB12F509BB6nielsbdevelopcom@.20
7.46.248.16...
> Unsafe managed code is one thing. P/Invoke to legacy C++ code is another.
> David
>
>sql
Is it possible to convert T-SQL 2005 to T-SQL 2000
I am working with the Web Service Software Factory and I have created my stored procedures that I will be needing. The problem is that when I try to apply the SP's to the database, I receive errors regarding the syntax. I am using SQL Server 2000 and it generates the script in 2005 T-SQL format. The script in 2005 is quite different from 2000 and I am not sure if converting it is even possible (eg. no try catch equivalent in 2000 and new error handling ). I searched msdn to check if I could specify the script version in WSSF, but I could not find anything. Any suggestions as to how I might solve this without purchasing SQL Server 2005?
The Web Service Software Factory had created this sql file that included the following function that is used throughout the file:
Code Snippet
IF NOT EXISTS (SELECT NAME FROM dbo.sysobjects WHERE TYPE = 'P' AND NAME = 'RethrowError')
BEGIN
EXEC('CREATE PROCEDURE [dbo].RethrowError AS RETURN')
END
GO
ALTER PROCEDURE RethrowError AS
/* Return if there is no error information to retrieve. */
IF ERROR_NUMBER() IS NULL
RETURN;
DECLARE
@.ErrorMessage NVARCHAR(4000),
@.ErrorNumber INT,
@.ErrorSeverity INT,
@.ErrorState INT,
@.ErrorLine INT,
@.ErrorProcedure NVARCHAR(200);
/* Assign variables to error-handling functions that
capture information for RAISERROR. */
SELECT
@.ErrorNumber = ERROR_NUMBER(),
@.ErrorSeverity = ERROR_SEVERITY(),
@.ErrorState = ERROR_STATE(),
@.ErrorLine = ERROR_LINE(),
@.ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-');
/* Building the message string that will contain original
error information. */
SELECT @.ErrorMessage =
N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' +
'Message: '+ ERROR_MESSAGE();
/* Raise an error: msg_str parameter of RAISERROR will contain
the original error information. */
RAISERROR(@.ErrorMessage, @.ErrorSeverity, 1,
@.ErrorNumber, /* parameter: original error number. */
@.ErrorSeverity, /* parameter: original error severity. */
@.ErrorState, /* parameter: original error state. */
@.ErrorProcedure, /* parameter: original error procedure name. */
@.ErrorLine /* parameter: original error line number. */
);
GO
And the error I receive is this ( I added 'machine\instance' to make it more generic):
Code Snippet
Msg 195, Level 15, State 10, Server Machine\Instance, Procedure RethrowError, Line 4
'ERROR_NUMBER' is not a recognized function name.
Msg 195, Level 15, State 10, Server Machine\Instance, Procedure RethrowError, Line 19
'ERROR_NUMBER' is not a recognized function name.
Msg 195, Level 15, State 10, Server Machine\Instance, Procedure RethrowError, Line 30
'ERROR_MESSAGE' is not a recognized function name.
Msg 170, Level 15, State 1, Server Machine\Instance, Procedure InsertUsers, Line 29
Line 29: Incorrect syntax near 'TRY'.
Msg 170, Level 15, State 1, Server Machine\Instance, Procedure InsertUsers, Line 37
Line 37: Incorrect syntax near 'TRY'.
Msg 156, Level 15, State 1, Server Machine\Instance, Procedure InsertUsers, Line 41
Incorrect syntax near the keyword 'END'.
Msg 156, Level 15, State 1, Server Machine\Instance, Procedure InsertUsers, Line 44
Incorrect syntax near the keyword 'END'.
Msg 170, Level 15, State 1, Server Machine\Instance, Procedure UpdateUsers, Line 31
Line 31: Incorrect syntax near 'TRY'.
Msg 170, Level 15, State 1, Server Machine\Instance, Procedure UpdateUsers, Line 40
Line 40: Incorrect syntax near 'TRY'.
Msg 156, Level 15, State 1, Server Machine\Instance, Procedure UpdateUsers, Line 44
Incorrect syntax near the keyword 'END'.
Msg 156, Level 15, State 1, Server Machine\Instance, Procedure UpdateUsers, Line 47
Incorrect syntax near the keyword 'END'.
The other errors involving the try-catch and end revolve around the try-catch syntax where it does not recognize the rethrowerror function.
Code Snippet
BEGIN TRY
Do Something
END TRY
BEGIN CATCH
EXEC RethrowError;
END CATCH
Any suggestions as to how I could convert this without having to rewrite the sql file generated the project tools? Thanks in advance.
You will have to remove the exception handling code (it is new in SQL Server 2005). You need to also remove references to the ERROR* functions. Only @.@.ERROR was available before.|||That seems so easy. I cant believe I didnt think of that on my own! Thanks for your help.Is it possible to convert the sample C# program AmoAdventureWorks in "C"?
Even a subset of AmoAdventureWorks would be fine (i.e with just one dimension, one measure etc.)
Please hepl me urgently!!!
ThanksHi.
It is not ideal, but with reflector (google reflector) can do it by reverse engineering.
Compile it, then load the PE into reflector, choose disassembly Managed C++.
Remember that case's can be goto's etc. because of the optimizations. I guess I would to compile it as debug.
Good luck|||Hi
Can anyone give me a sample code in "C" for the C# Code sample for AMO Adventureworks?
I dont need whole code, please give a sample code in "C" with just 1 dimension and 1 measuregroup for Adventure works 2005 Cubes that uses AMO, thats fair enough..I can manage from there.
Can anyone please help me in the above issue?
I'm urgently in need of help!!!!!
Even a link having the Sample C code for Adventureworks 2005 cubes with AMO is also fne.
Thanks in Advance
Shaun
Monday, March 12, 2012
Is it possiable conversion
i heared that Oracle can convert from number to word thru query i
remember thru (jsp format) .Is it possiable in sqlserver
ThanksHi
Although I have not done this myslf, you may want to look at either:
Creating an RTF document
Creating a txt document and a word macro to format and save it
Using a COM object (called from sp_AO* procedures)
Using XML and a word template that picks it up.
Sucking data from SQL Server into word
John
"Raghuraman" <raghuraman_ace@.rediffmail.com> wrote in message
news:66c7bef8.0311140440.4738e50d@.posting.google.c om...
> Hi
> i heared that Oracle can convert from number to word thru query i
> remember thru (jsp format) .Is it possiable in sqlserver
>
>
> Thanks
Monday, February 20, 2012
Is are a way to convert the SQL datetime to MFC CTime
Here is the time in SQL : 2/21/2003 12:00:00 PM (DataType :datetime)
How can i convert this into CTime .the MFC class
Help inthis regard is appreciated,
Thanks in AdvanceA datetime is not that format. It is a decimal number - that is just the way it is converted for display.
What format do you need it in to put into a CTime.|||Thanks 'nigelrivett' for replying me
Yes...I reading the date(datetime) from the Data Base as the String..I want Month,Year,Date,Hour and Minute to build the Time for my application.
i like to build the CTime as below:
CTime Ts(nYear,nMonth,nDate,nHour,nMinute,nSecond,o);
So please tell me how get the Hour,minute,Day,Year from the Data Base.
Thanks in advance,
Sirish|||try:
select getdate() as 'Original Date'
, datepart(yy,getdate()) as 'Year'
, datepart(mm,getdate()) as 'Month'
, datepart(dd,getdate()) as 'Day'
, datepart(hh,getdate()) as 'Hour'
, datepart(mi,getdate()) as 'Minute'
, datepart(ss,getdate()) as 'Second'
, datepart(ms,getdate()) as 'Millisecond'