Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Sunday, March 25, 2012

Cant sort a text field!

Hi
ive got a table and contains a surname text field. Why cant i do a select statement ORDER BY surname. I get an error saying i cant sort a text field! how do i go around it!

thanksYou do ANSI SQL ALTER Table and change text to Varchar 40 because text cannot be used for things like name that can be covered with Varchar 40 or 50 at most. Then do ORDER BY. Hope this helps.|||

Your surname filed is a text datatype field which cannot be sorted.

You need change this field to varchar(50) or nvarchar(50) data type to allow you sort on it.

Limno

Thursday, March 22, 2012

Cant select Date

hi, my DatePost field in the database formated as2/15/2006 11:40:46 AM .i try to manually give a date (no) but it give me error. the error come from myReader!. help me to correct, thanks

no = "2152006"
Dim myConn As SqlConnection
Dim myCmd As SqlCommand = New SqlCommand
Dim myReader As SqlDataReader
Dim strSQL As String

myConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
strSQL ="SELECT Author FROM Booktbl WHERE cast(Date as datetime) ='" & no & "'"
myCmd.CommandText = strSQL
myConn.Open()
myCmd.Connection = myConn
myReader = myCmd.ExecuteReader
myReader.Read()

Author = myReader("Author")

myReader.Close()
myConn.Close()
lblShow.Text = Subject

Hello Sebastian,

Try adding slashes to your date string like this:

no = "2/15/2006"

Even better would be to use a variable of DateTime type like this:

Dim no As DateTime
no = "2/15/2006"

This should solve your problem.

Regards, Maurits

|||

If you used no="20060215" then your query would be correct, but it still would not return any records, because the datetime "2006-15-02 11:40:46" <> "2006-15-02 00:00:00".

no = "20060215" -- assume string is in YYYYMMDD format so SQL Server can implicitly convert it to a datetime for comparision (OR any string recognized by SQL Server's current language/culture setting)
Dim myConn As SqlConnection
Dim myCmd As SqlCommand = New SqlCommand
Dim myReader As SqlDataReader
Dim strSQL As String

myConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
strSQL ="SELECT Author FROM Booktbl WHERE cast(Date as datetime) ='" & no & "'"
myCmd.CommandText = strSQL
myConn.Open()
myCmd.Connection = myConn
myReader = myCmd.ExecuteReader
myReader.Read()

Author = myReader("Author")

myReader.Close()
myConn.Close()
lblShow.Text = Subject

I'm going to assume you know how to make no a datetime variable instead of a string, but assuming it is a datetime with a time portion being midnight, this should do what you want:

Dim myConn As new SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
myConn.open
Dim myCmd As SqlCommand = New SqlCommand("SELECT Author FROM Booktbl WHERE cast(Date as datetime) >=@.no AND cast(Date as datetime)<dateadd(d,1,@.no)",myConn)
myCmd.parameters.add("@.no",sqldbtype.datetime).value=no
lblShow.Text = myCmd.executeScalar
myConn.Close()

Actually, the above code will work even if no is string that contains a datetime in a format that is understood by the culture the ASP.NET thread is running too. (For example "2/15/2006" if the current culture is US-en, or "15-02-2006" if the current culture is FR-fr", etc.)

|||Two things to keep in mind when working with datetime column types.

1. Datetime type contains two components: date and time. So, when specifying WHERE clause, you have to consider the time component as well. By default, datetime's time component is "12:00:00 AM". So, if you're trying to filter for date of "02-20-2006', the something similar to following would be used:

... WHERE DATE_COL >= '02-20-2006' AND DATE_COL< '02-21-2006'

(notice the less-than sign and the date of one more than the one intended in query)

or

... WHERE DATE_COL >= '02-20-2006 12:00:00 AM' AND DATE_COL<= '02-20-2006 11:59:59 PM'

2. As in the example above, you need to provide a specific format of date string. Your value of "2152006" is confusing to the translation engine, so transform it to something like "mm-dd-yyyy", "mm/dd/yyyy" or even "yyyymmdd" which is the ISO version.|||

WHERE DATE_COL >= '02-20-2006' AND DATE_COL< '02-21-2006'

is really what you should use, the statement

WHERE DATE_COL >= '02-20-2006 12:00:00 AM' AND DATE_COL<= '02-20-2006 11:59:59 PM'

actually has two issues. First, if you use that with a datetime column, since the datetime field is accurate to approximately 1/300th of a second, there is really a 1-second gap that the query will not find. You could conceivably do something like:

WHERE DATE_COL >= '02-20-2006 12:00:00 AM' AND DATE_COL<= '02-20-2006 11:59:59.997 PM'

but that assumes you know the exact highest time value that is storable in a datetime field, which I prefer not to use (assume). It's inviting problems on upgrades, conversion, or database migration to another platform. Secondly, if you tried to do that with a smalldatetime field, SQL Server will convert the strings to a smalldatetime, and since that is only accurate to 2 seconds, it will round your string to the nearest 2-second interval (Since it is half way between, it will round UP), giving you 02-21-2006 00:00:00, which will include any smalldatetimes that are part of midnight the next day, also very yucky.

|||

jcasp wrote:

Two things to keep in mind when working with datetime column types.

... WHERE DATE_COL >= '02-20-2006' AND DATE_COL< '02-21-2006'

or

... WHERE DATE_COL >= '02-20-2006 12:00:00 AM' AND DATE_COL<= '02-20-2006 11:59:59 PM'


I'd definitely stick with that first WHERE clause. The second one is not taking milliseconds into consideration. And I prefer using the ISO version of the date '20060215' as it is unanmbiguous.

Motley wrote:


Dim myCmd As SqlCommand = New SqlCommand("SELECT Author FROM Booktbl WHERE cast(Date as datetime) >=@.no AND cast(Date as datetime)<dateadd(d,1,@.no)",myConn)


You want to stay away from this approach Don't use a function against a column like that; it really increases the overhead in running the query as the fuction has to be performed against every row. Stick with the approach suggested by jcasp.|||Correction noted. One should keep in mind that datetime column type does have higher precision than the second component (goes to milliseconds). Very easy to overlook, but can definitely come into play. Good catch.|||

tmorton wrote:

jcasp wrote:

Two things to keep in mind when working with datetime column types.

... WHERE DATE_COL >= '02-20-2006' AND DATE_COL< '02-21-2006'

or

... WHERE DATE_COL >= '02-20-2006 12:00:00 AM' AND DATE_COL<= '02-20-2006 11:59:59 PM'


I'd definitely stick with that first WHERE clause. The second one is not taking milliseconds into consideration. And I prefer using the ISO version of the date '20060215' as it is unanmbiguous.

Motley wrote:


Dim myCmd As SqlCommand = New SqlCommand("SELECT Author FROM Booktbl WHERE cast(Date as datetime) >=@.no AND cast(Date as datetime)<dateadd(d,1,@.no)",myConn)


You want to stay away from this approach Don't use a function against a column like that; it really increases the overhead in running the query as the fuction has to be performed against every row. Stick with the approach suggested by jcasp.

Actually, what I wrote is the only method mentioned here that will actually work, assuming that the field "Date" is actually a varchar field. Since the original poster said his "PostDate" field had a format of "MM/DD/YYYY HH:MM:SS PM", and datetimes don't have a format, this was my assumption. Of course, if the original poster was incorrect, and the field is actually a datetime, then just drop the cast portion of my command. Since the DateAdd function is a deterministic function, and it's input is based on the parameters, SQL Server will only need to execute this once instead of every row.

|||ok, before i select the author record, i have insert a date record into the table. this is how i do.

Dim Date As Date = Now()

Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
Dim myCommand As New SqlCommand("INSERT INTO Booktbl (Author, Date) VALUES('" & strAuthor & "', '" & Date & "')", myConnection)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

Catch ex As SqlException
lblMsg.Text = " Error"
End Try
End Sub

End insert section. the data type used to store date is datetime. the record look like this 2/12/2006 11:40:40 AM

when i try to retrive back the record base on the date it give me error. i also declare the no as date, datetime or string and put it "2/12/2006" or some other format it still not work. i have try one example to put the no = "2/12/2006 11:40:40 AM" then it work, but what i need is the date not the time.

anymore figure out what happen??|||Dim MyDate As Datetime = Now()

Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
Dim myCommand As New SqlCommand("INSERT INTO Booktbl (Author, Date) VALUES(@.author,@.MyDate)", myConnection)
myCommand.parameters.add("@.author",sqdbtype.varchar).value=strAuthor
myCommand.parameters.add("@.MyDate",sqldbtype.datetime).value=MyDate
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

Catch ex As SqlException
lblMsg.Text = " Error"
End Try
End Sub|||Motley, i have used your code to insert data to the table. now i want to select the info and display it. This is how i do it!

Dim no As DateTime
no = "2/22/2006"

Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
Dim myCommand As New SqlCommand("SELECT Author FROM Booktbl WHERE Date = @.no", myConnection)
myCommand.Parameters.Add("@.no", SqlDbType.DateTime).Value = no
myConnection.Open()

Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader()
myReader.Read()

Author = myReader("Author")

myReader.Close()
myConnection.Close()
lblShow2.Text = Author

it give me this error message "Invalid attempt to read when no data is present."why? why i can't retrive the data? i been work on this few days ago, hope u can help me. thanks
|||

Because the datetimes aren't exactly the same.

SELECT Author FROM Booktbl WHERE dateadd(d,0,datediff(d,0,Date)) = dateadd(d,0,datediff(d,0,@.no))

is the select statement you want if you just want the date portions to match.

SELECT Author FROM Booktbl WHERE Date>=dateadd(d,0,datediff(d,0,@.no)) AND Date<dateadd(d,1,datediff(d,0,@.no))

is the same idea, but will execute much faster, it's looking for a datetime >= to the beginning of the day in @.no through (but not including) the beginning of the day after @.no. (Between 2/22/2006 @. midnight through 2/23/2006 @. midnight)

sql

Can't select a datetime field in a query without time portion

Hi,
I am doing some project with SQL Server 2000 and C#. I am using a
SELECT statement to get a column and to bind it to a dropdown list. The
column is a datetime format. I don't need time portion of it. Before I
tried any CONVERT functions my query looked like this:
SELECT DISTINCT DateEntered FROM TBL_PTM_Report
I can get the data this way but only with time portion in it. I read
about CONVERT but can't get it working. I am getting all kinds of error
messages from Visual Studio.
I tried the lowwoling:
SELECT COVVERT(CHAR(10), DateEntered, 101) FROM TBL_PTM_Report
It didn't work. I need data in the following format MM/DD/YYYY
Thank you,
Stan> SELECT COVVERT(CHAR(10), DateEntered, 101) FROM TBL_PTM_Report
CONVERT.
AMB
"suslishe@.mail.ru" wrote:

> Hi,
> I am doing some project with SQL Server 2000 and C#. I am using a
> SELECT statement to get a column and to bind it to a dropdown list. The
> column is a datetime format. I don't need time portion of it. Before I
> tried any CONVERT functions my query looked like this:
> SELECT DISTINCT DateEntered FROM TBL_PTM_Report
> I can get the data this way but only with time portion in it. I read
> about CONVERT but can't get it working. I am getting all kinds of error
> messages from Visual Studio.
> I tried the lowwoling:
>
> SELECT COVVERT(CHAR(10), DateEntered, 101) FROM TBL_PTM_Report
> It didn't work. I need data in the following format MM/DD/YYYY
> Thank you,
> Stan
>|||This was my typing mistake, sorry! The statement looks like this:
SELECT CONVERT(CHAR(10), DateEntered, 101) FROM TBL_PTM_Report|||I just ran this in query analyser and everything works! But Visual
Studio gives me an error.

Can't seem to get the newly created entry's identity field :(

Hi there,

I have a stored procedure that executes a transaction which updates/inserts into a table on a remote server and should then use that new entry's autogenerated primary key to update another table.
I try to store that key into a variable called @.NewlyCreatedPastelDClinkNumber but to no avail

I have used the @.@.Identity approach and now try to manually get that key to from other information but still no go..My thinking is: since i am using transactions, maybe the entry cant be found until the transaction has been committed...but surely it should find it after the commit statement? Here is my code: I have marked the interesting bit with blue for simplicity.

ALTER procedure [dbo].[inv_SynchronizeClientsWithPastel]
as
BEGIN
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
SET XACT_ABORT ON

DECLARE @.PastelDCLinkNumber int
DECLARE @.ClientID int
DECLARE @.Name varchar(25)
DECLARE @.Surname nvarchar(25)
DECLARE @.POBoxAddr1 varchar(40)
DECLARE @.POBoxAddr2 varchar(40)
DECLARE @.PostalCode varchar(5)
DECLARE @.ClientCreditCardNumber nvarchar(50)
DECLARE @.NewlyCreatedPastelDClinkNumber int
DECLARE PastelClientPortCursor CURSOR FOR

SELECT id, [Name], Surname, POBoxAddr1, POBoxAddr2, PostalCode, PastelDCLinkNumber ,CreditCardNumber
FROM inc_Client
WHERE HasSynchronizedWithPastel = 0

OPEN PastelClientPortCursor;
FETCH NEXT FROM PastelClientPortCursor
INTO @.ClientID,@.Name,@.Surname,@.POBoxAddr1,@.POBoxAddr2,@.PostalCode,@.PastelDCLinkNumber,@.ClientCreditCardNumber
WHILE @.@.FETCH_STATUS = 0
BEGIN

--Step2 insert/update the client information into the Synergy invoice and client table
BEGIN TRANSACTION T1
IF Exists(SELECT DCLink from [server].[Satra Corporate (Pty) Ltd].dbo.Client WHERE DCLink = @.PastelDCLinkNumber)

--Update the Pastel Client table

Begin
Update [server].[Satra Corporate (Pty) Ltd].dbo.Client SET
Name = (@.Name + ' ' + @.Surname),
Account = (@.Name + ' ' + @.Surname),
Post1 = @.POBoxAddr1,
Post2 = @.POBoxAddr2,
PostPC = @.PostalCode,
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber
WHERE DCLink = @.PastelDCLinkNumber
End

ELSE
Begin
--Insert into the Pastel Client table
INSERT INTO [server].[Satra Corporate (Pty) Ltd].dbo.Client
(Account, Name, Post1, Post2, PostPC, AccountTerms, CT, Credit_Limit,
RepID, Interest_Rate, Discount, On_Hold, BFOpenType, BankLink,
AutoDisc,
DiscMtrxRow, CashDebtor, DCBalance, CheckTerms, UseEmail,
iCountryID, cAccDescription, iCurrencyID, bStatPrint,
bStatEmail, bForCurAcc,
fForeignBalance, bTaxPrompt, iARPriceListNameID)
VALUES
(
SUBSTRING(@.Name, 1,19), --Account
(@.Name + ' ' + @.Surname), --Name
@.POBoxAddr1, --Post1
@.POBoxAddr2, --Post2
@.PostalCode, --PostPC
0, --Account_Terms
1, --CT
0,--Credit_Limit
0, --Rep_ID
0, --interest_Rate
0, --Discount
0, --On_Hold
0, --BFOpenType
0, --BankLink
0, --AutoDisc
0, --DiscMatrix
0, --CashDebtor
0, --DCBalance
1, --CheckTerms
0, --UseEmail
0, --iCountryID
'Credit Card Number: ' + @.ClientCreditCardNumber,
0, --iCurrencyID
1, --StatPrint
0, --StatEmail
0, --bForCurAcc
0, --ForeignBal
1, --bTaxPrompt
1 --iARPriceListNameID
)
End

--If the rowcount is 0, an error has occured
IF @.@.ROWCOUNT <> 0
Begin
COMMIT TRANSACTION T1
execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag

Begin
SET @.NewlyCreatedPastelDClinkNumber = (SELECT DCLink From [server].[Satra Corporate (Pty) Ltd].dbo.Client
WHERE Name = (@.Name + ' ' + @.Surname)AND
Account = (@.Name + ' ' + @.Surname)AND
Post1 = @.POBoxAddr1 AND
Post2 = @.POBoxAddr2 AND
PostPC = @.PostalCode AND
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber)
End

Begin
Update inc_Client SET
HasSynchronizedWithPastel = 1 ,
PastelDCLinkNumber = @.NewlyCreatedPastelDClinkNumber
WHERE id = @.ClientID
End
End

--Rollback transaction
IF @.@.TRANCOUNT > 0
Begin
ROLLBACK TRANSACTION T1
execute sec_LogSQLTransactionError 'inv_SynchronizeClientsWithPastel','inc_Client_id',@.ClientID,'System'
End

FETCH NEXT FROM PastelClientPortCursor
INTO @.ClientID,@.Name,@.Surname,@.POBoxAddr1,@.POBoxAddr2,@.PostalCode,@.PastelDCLinkNumber, @.ClientCreditCardNumber
END
CLOSE PastelClientPortCursor;
DEALLOCATE PastelClientPortCursor;

END

SET XACT_ABORT OFF
Go

Instead of:

COMMIT TRANSACTION T1
execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag

Begin
SET @.NewlyCreatedPastelDClinkNumber = (SELECT DCLink From [server].[Satra Corporate (Pty) Ltd].dbo.Client
WHERE Name = (@.Name + ' ' + @.Surname)AND
Account = (@.Name + ' ' + @.Surname)AND
Post1 = @.POBoxAddr1 AND
Post2 = @.POBoxAddr2 AND
PostPC = @.PostalCode AND
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber)
End

Try:

COMMIT TRANSACTION T1

SET @.NewlyCreatedPastelDClinkNumber = scope_identity()

execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag


|||

Problem 1)

IF Exists(SELECT DCLink from [server].[Satra Corporate (Pty) Ltd].dbo.Client WHERE DCLink = @.PastelDCLinkNumber)

--Update the Pastel Client table

Begin
Update [server].[Satra Corporate (Pty) Ltd].dbo.Client SET

Don't check for the data and then do the update. Simply DO the update first. If you update 0 rows, then you do the insert. This cuts exection in half when there is an update to be performed.

Problem 2)

IMMEDIATELY after the INSERT, put the @.@.ERROR and @.@.ROWCOUNT AND scope_identity() values into a variable. Then act on those three in appropriate order.

Problem 3)

You should use a remote sproc to do the update/insert stuff on the remote server. MUCH more efficient. Pass parameters in and then local stuff does work with a cached query plan and only one network trip.

|||Thanks for all your support. I'm going to give this a try|||Thank you for all your help. It worked.

I looked at your suggestions in your steps(problems) and immediately saw the advantages of your suggestions.

I will now adapt future stored procedure's templates to include those good practices. Thanks once more.

Regards
Mike

Can't seem to get the newly created entry's identity field :(

Hi there,

I have a stored procedure that executes a transaction which updates/inserts into a table on a remote server and should then use that new entry's autogenerated primary key to update another table.
I try to store that key into a variable called @.NewlyCreatedPastelDClinkNumber but to no avail

I have used the @.@.Identity approach and now try to manually get that key to from other information but still no go..My thinking is: since i am using transactions, maybe the entry cant be found until the transaction has been committed...but surely it should find it after the commit statement? Here is my code: I have marked the interesting bit with blue for simplicity.

ALTER procedure [dbo].[inv_SynchronizeClientsWithPastel]
as
BEGIN
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
SET XACT_ABORT ON

DECLARE @.PastelDCLinkNumber int
DECLARE @.ClientID int
DECLARE @.Name varchar(25)
DECLARE @.Surname nvarchar(25)
DECLARE @.POBoxAddr1 varchar(40)
DECLARE @.POBoxAddr2 varchar(40)
DECLARE @.PostalCode varchar(5)
DECLARE @.ClientCreditCardNumber nvarchar(50)
DECLARE @.NewlyCreatedPastelDClinkNumber int
DECLARE PastelClientPortCursor CURSOR FOR

SELECT id, [Name], Surname, POBoxAddr1, POBoxAddr2, PostalCode, PastelDCLinkNumber ,CreditCardNumber
FROM inc_Client
WHERE HasSynchronizedWithPastel = 0

OPEN PastelClientPortCursor;
FETCH NEXT FROM PastelClientPortCursor
INTO @.ClientID,@.Name,@.Surname,@.POBoxAddr1,@.POBoxAddr2,@.PostalCode,@.PastelDCLinkNumber,@.ClientCreditCardNumber
WHILE @.@.FETCH_STATUS = 0
BEGIN

--Step2 insert/update the client information into the Synergy invoice and client table
BEGIN TRANSACTION T1
IF Exists(SELECT DCLink from [server].[Satra Corporate (Pty) Ltd].dbo.Client WHERE DCLink = @.PastelDCLinkNumber)

--Update the Pastel Client table

Begin
Update [server].[Satra Corporate (Pty) Ltd].dbo.Client SET
Name = (@.Name + ' ' + @.Surname),
Account = (@.Name + ' ' + @.Surname),
Post1 = @.POBoxAddr1,
Post2 = @.POBoxAddr2,
PostPC = @.PostalCode,
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber
WHERE DCLink = @.PastelDCLinkNumber
End

ELSE
Begin
--Insert into the Pastel Client table
INSERT INTO [server].[Satra Corporate (Pty) Ltd].dbo.Client
(Account, Name, Post1, Post2, PostPC, AccountTerms, CT, Credit_Limit,
RepID, Interest_Rate, Discount, On_Hold, BFOpenType, BankLink,
AutoDisc,
DiscMtrxRow, CashDebtor, DCBalance, CheckTerms, UseEmail,
iCountryID, cAccDescription, iCurrencyID, bStatPrint,
bStatEmail, bForCurAcc,
fForeignBalance, bTaxPrompt, iARPriceListNameID)
VALUES
(
SUBSTRING(@.Name, 1,19), --Account
(@.Name + ' ' + @.Surname), --Name
@.POBoxAddr1, --Post1
@.POBoxAddr2, --Post2
@.PostalCode, --PostPC
0, --Account_Terms
1, --CT
0,--Credit_Limit
0, --Rep_ID
0, --interest_Rate
0, --Discount
0, --On_Hold
0, --BFOpenType
0, --BankLink
0, --AutoDisc
0, --DiscMatrix
0, --CashDebtor
0, --DCBalance
1, --CheckTerms
0, --UseEmail
0, --iCountryID
'Credit Card Number: ' + @.ClientCreditCardNumber,
0, --iCurrencyID
1, --StatPrint
0, --StatEmail
0, --bForCurAcc
0, --ForeignBal
1, --bTaxPrompt
1 --iARPriceListNameID
)
End

--If the rowcount is 0, an error has occured
IF @.@.ROWCOUNT <> 0
Begin
COMMIT TRANSACTION T1
execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag

Begin
SET @.NewlyCreatedPastelDClinkNumber = (SELECT DCLink From [server].[Satra Corporate (Pty) Ltd].dbo.Client
WHERE Name = (@.Name + ' ' + @.Surname)AND
Account = (@.Name + ' ' + @.Surname)AND
Post1 = @.POBoxAddr1 AND
Post2 = @.POBoxAddr2 AND
PostPC = @.PostalCode AND
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber)
End

Begin
Update inc_Client SET
HasSynchronizedWithPastel = 1 ,
PastelDCLinkNumber = @.NewlyCreatedPastelDClinkNumber
WHERE id = @.ClientID
End
End

--Rollback transaction
IF @.@.TRANCOUNT > 0
Begin
ROLLBACK TRANSACTION T1
execute sec_LogSQLTransactionError 'inv_SynchronizeClientsWithPastel','inc_Client_id',@.ClientID,'System'
End

FETCH NEXT FROM PastelClientPortCursor
INTO @.ClientID,@.Name,@.Surname,@.POBoxAddr1,@.POBoxAddr2,@.PostalCode,@.PastelDCLinkNumber, @.ClientCreditCardNumber
END
CLOSE PastelClientPortCursor;
DEALLOCATE PastelClientPortCursor;

END

SET XACT_ABORT OFF
Go

Instead of:

COMMIT TRANSACTION T1
execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag

Begin
SET @.NewlyCreatedPastelDClinkNumber = (SELECT DCLink From [server].[Satra Corporate (Pty) Ltd].dbo.Client
WHERE Name = (@.Name + ' ' + @.Surname)AND
Account = (@.Name + ' ' + @.Surname)AND
Post1 = @.POBoxAddr1 AND
Post2 = @.POBoxAddr2 AND
PostPC = @.PostalCode AND
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber)
End

Try:

COMMIT TRANSACTION T1

SET @.NewlyCreatedPastelDClinkNumber = scope_identity()

execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag


|||

Problem 1)

IF Exists(SELECT DCLink from [server].[Satra Corporate (Pty) Ltd].dbo.Client WHERE DCLink = @.PastelDCLinkNumber)

--Update the Pastel Client table

Begin
Update [server].[Satra Corporate (Pty) Ltd].dbo.Client SET

Don't check for the data and then do the update. Simply DO the update first. If you update 0 rows, then you do the insert. This cuts exection in half when there is an update to be performed.

Problem 2)

IMMEDIATELY after the INSERT, put the @.@.ERROR and @.@.ROWCOUNT AND scope_identity() values into a variable. Then act on those three in appropriate order.

Problem 3)

You should use a remote sproc to do the update/insert stuff on the remote server. MUCH more efficient. Pass parameters in and then local stuff does work with a cached query plan and only one network trip.

|||Thanks for all your support. I'm going to give this a try|||Thank you for all your help. It worked.

I looked at your suggestions in your steps(problems) and immediately saw the advantages of your suggestions.

I will now adapt future stored procedure's templates to include those good practices. Thanks once more.

Regards
Mikesql

Can''t seem to get the newly created entry''s identity field :(

Hi there,

I have a stored procedure that executes a transaction which updates/inserts into a table on a remote server and should then use that new entry's autogenerated primary key to update another table.
I try to store that key into a variable called @.NewlyCreatedPastelDClinkNumber but to no avail

I have used the @.@.Identity approach and now try to manually get that key to from other information but still no go..My thinking is: since i am using transactions, maybe the entry cant be found until the transaction has been committed...but surely it should find it after the commit statement? Here is my code: I have marked the interesting bit with blue for simplicity.

ALTER procedure [dbo].[inv_SynchronizeClientsWithPastel]
as
BEGIN
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
SET XACT_ABORT ON

DECLARE @.PastelDCLinkNumber int
DECLARE @.ClientID int
DECLARE @.Name varchar(25)
DECLARE @.Surname nvarchar(25)
DECLARE @.POBoxAddr1 varchar(40)
DECLARE @.POBoxAddr2 varchar(40)
DECLARE @.PostalCode varchar(5)
DECLARE @.ClientCreditCardNumber nvarchar(50)
DECLARE @.NewlyCreatedPastelDClinkNumber int
DECLARE PastelClientPortCursor CURSOR FOR

SELECT id, [Name], Surname, POBoxAddr1, POBoxAddr2, PostalCode, PastelDCLinkNumber ,CreditCardNumber
FROM inc_Client
WHERE HasSynchronizedWithPastel = 0

OPEN PastelClientPortCursor;
FETCH NEXT FROM PastelClientPortCursor
INTO @.ClientID,@.Name,@.Surname,@.POBoxAddr1,@.POBoxAddr2,@.PostalCode,@.PastelDCLinkNumber,@.ClientCreditCardNumber
WHILE @.@.FETCH_STATUS = 0
BEGIN

--Step2 insert/update the client information into the Synergy invoice and client table
BEGIN TRANSACTION T1
IF Exists(SELECT DCLink from [server].[Satra Corporate (Pty) Ltd].dbo.Client WHERE DCLink = @.PastelDCLinkNumber)

--Update the Pastel Client table

Begin
Update [server].[Satra Corporate (Pty) Ltd].dbo.Client SET
Name = (@.Name + ' ' + @.Surname),
Account = (@.Name + ' ' + @.Surname),
Post1 = @.POBoxAddr1,
Post2 = @.POBoxAddr2,
PostPC = @.PostalCode,
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber
WHERE DCLink = @.PastelDCLinkNumber
End

ELSE
Begin
--Insert into the Pastel Client table
INSERT INTO [server].[Satra Corporate (Pty) Ltd].dbo.Client
(Account, Name, Post1, Post2, PostPC, AccountTerms, CT, Credit_Limit,
RepID, Interest_Rate, Discount, On_Hold, BFOpenType, BankLink,
AutoDisc,
DiscMtrxRow, CashDebtor, DCBalance, CheckTerms, UseEmail,
iCountryID, cAccDescription, iCurrencyID, bStatPrint,
bStatEmail, bForCurAcc,
fForeignBalance, bTaxPrompt, iARPriceListNameID)
VALUES
(
SUBSTRING(@.Name, 1,19), --Account
(@.Name + ' ' + @.Surname), --Name
@.POBoxAddr1, --Post1
@.POBoxAddr2, --Post2
@.PostalCode, --PostPC
0, --Account_Terms
1, --CT
0,--Credit_Limit
0, --Rep_ID
0, --interest_Rate
0, --Discount
0, --On_Hold
0, --BFOpenType
0, --BankLink
0, --AutoDisc
0, --DiscMatrix
0, --CashDebtor
0, --DCBalance
1, --CheckTerms
0, --UseEmail
0, --iCountryID
'Credit Card Number: ' + @.ClientCreditCardNumber,
0, --iCurrencyID
1, --StatPrint
0, --StatEmail
0, --bForCurAcc
0, --ForeignBal
1, --bTaxPrompt
1 --iARPriceListNameID
)
End

--If the rowcount is 0, an error has occured
IF @.@.ROWCOUNT <> 0
Begin
COMMIT TRANSACTION T1
execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag

Begin
SET @.NewlyCreatedPastelDClinkNumber = (SELECT DCLink From [server].[Satra Corporate (Pty) Ltd].dbo.Client
WHERE Name = (@.Name + ' ' + @.Surname)AND
Account = (@.Name + ' ' + @.Surname)AND
Post1 = @.POBoxAddr1 AND
Post2 = @.POBoxAddr2 AND
PostPC = @.PostalCode AND
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber)
End

Begin
Update inc_Client SET
HasSynchronizedWithPastel = 1 ,
PastelDCLinkNumber = @.NewlyCreatedPastelDClinkNumber
WHERE id = @.ClientID
End
End

--Rollback transaction
IF @.@.TRANCOUNT > 0
Begin
ROLLBACK TRANSACTION T1
execute sec_LogSQLTransactionError 'inv_SynchronizeClientsWithPastel','inc_Client_id',@.ClientID,'System'
End

FETCH NEXT FROM PastelClientPortCursor
INTO @.ClientID,@.Name,@.Surname,@.POBoxAddr1,@.POBoxAddr2,@.PostalCode,@.PastelDCLinkNumber, @.ClientCreditCardNumber
END
CLOSE PastelClientPortCursor;
DEALLOCATE PastelClientPortCursor;

END

SET XACT_ABORT OFF
Go

Instead of:

COMMIT TRANSACTION T1
execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag

Begin
SET @.NewlyCreatedPastelDClinkNumber = (SELECT DCLink From [server].[Satra Corporate (Pty) Ltd].dbo.Client
WHERE Name = (@.Name + ' ' + @.Surname)AND
Account = (@.Name + ' ' + @.Surname)AND
Post1 = @.POBoxAddr1 AND
Post2 = @.POBoxAddr2 AND
PostPC = @.PostalCode AND
cAccDescription = 'Credit Card Number: ' + @.ClientCreditCardNumber)
End

Try:

COMMIT TRANSACTION T1

SET @.NewlyCreatedPastelDClinkNumber = scope_identity()

execute sec_LogSQLTransaction 'inv_SynchronizeClientsWithPastel' ,'inc_Client_id',@.ClientID,'System'
-- Step 3Update the HasSynchronizedWithPastel Flag


|||

Problem 1)

IF Exists(SELECT DCLink from [server].[Satra Corporate (Pty) Ltd].dbo.Client WHERE DCLink = @.PastelDCLinkNumber)

--Update the Pastel Client table

Begin
Update [server].[Satra Corporate (Pty) Ltd].dbo.Client SET

Don't check for the data and then do the update. Simply DO the update first. If you update 0 rows, then you do the insert. This cuts exection in half when there is an update to be performed.

Problem 2)

IMMEDIATELY after the INSERT, put the @.@.ERROR and @.@.ROWCOUNT AND scope_identity() values into a variable. Then act on those three in appropriate order.

Problem 3)

You should use a remote sproc to do the update/insert stuff on the remote server. MUCH more efficient. Pass parameters in and then local stuff does work with a cached query plan and only one network trip.

|||Thanks for all your support. I'm going to give this a try|||Thank you for all your help. It worked.

I looked at your suggestions in your steps(problems) and immediately saw the advantages of your suggestions.

I will now adapt future stored procedure's templates to include those good practices. Thanks once more.

Regards
Mike

Tuesday, March 20, 2012

Can''t see named sets in Excel 2007

Hi there,

I am not able to see the named sets in the PivotTable Field List in Excel 2007. I created e.g. the simple named set

CREATE SET CURRENTCUBE.[Austria]
AS [CUSTOMER].[COUNTRY].&[Austria] ;

Then I changed the display folder to 'Special Countries' in the mask 'Calculation properties' without selecting an 'Associated Measure Group'. After building the cube I can even see that display folder in the left-side tree of the 'Browse' window.
But after connecting to the cube with Excel 2007 the named set is not available for selection.

It seems that I am missing an important point.

Best wishes from Austria,

nedvin

I'm using Excel 2007 against the Adventure Works DW database and the Adventure Works cube. In the Account dimension, I see the [Summary P&L] named set. It has a Display folder of Sets and an Associated Measure Group of Financial Reporting.

You may want to compare what you have to what is in Adventure Works.

B.

|||Hi Bryan,

it took some time to install the Adventure Works Cube (actually I have completely reinstalled my pc), sorry for the late reply.
But even with your example I am unable to find the named set in the PivotTable Field List in Excel 2007. There is simply no folder 'Sets' containing the named set [Summary P&L].
I do see the [Summary P&L] in the cube (in the specified folder) and it is well defined under the mask 'Calculation properties', but in Excel 2007 it is not listed.

Kind regards,

nedvin
|||

I can see [Summary P&L] under the Account dimension. I use the enterprise edition version of the Adventure Works cube project. Make sure that you see the whole cube and not only a perspective("Show related fields to" at the top of the dimension tool)

HTH

Thomas Ivarsson

|||
Hi Thomas,

thank you for your reply.
I am using the Aventure Works cube project entreprise edition as well.In Excel 2007 the dropdown list 'Show fields related to' is set to the property 'All', so I think that I am not restricted to a perspective.
I can browse the cube in the SQL Server Management Studio(as well as in the BI Development Studio) and see the named sets as defined, but with Excel 2007 the named sets are not listed (neither the [Summary P&L] under the Account dimension nor the folder 'Sets' with 'Core Product Group', 'Long Lead Products',.... under the Product dimension).
By the way, I have Excel 2007 (12.0.6024.5000) MSO(12.0.6017.5000). Maybe I have a different version of Excel 2007?

Kind regards,
nedvin

Can''t see named sets in Excel 2007

Hi there,

I am not able to see the named sets in the PivotTable Field List in Excel 2007. I created e.g. the simple named set

CREATE SET CURRENTCUBE.[Austria]
AS [CUSTOMER].[COUNTRY].&[Austria] ;

Then I changed the display folder to 'Special Countries' in the mask 'Calculation properties' without selecting an 'Associated Measure Group'. After building the cube I can even see that display folder in the left-side tree of the 'Browse' window.
But after connecting to the cube with Excel 2007 the named set is not available for selection.

It seems that I am missing an important point.

Best wishes from Austria,

nedvin

I'm using Excel 2007 against the Adventure Works DW database and the Adventure Works cube. In the Account dimension, I see the [Summary P&L] named set. It has a Display folder of Sets and an Associated Measure Group of Financial Reporting.

You may want to compare what you have to what is in Adventure Works.

B.

|||Hi Bryan,

it took some time to install the Adventure Works Cube (actually I have completely reinstalled my pc), sorry for the late reply.
But even with your example I am unable to find the named set in the PivotTable Field List in Excel 2007. There is simply no folder 'Sets' containing the named set [Summary P&L].
I do see the [Summary P&L] in the cube (in the specified folder) and it is well defined under the mask 'Calculation properties', but in Excel 2007 it is not listed.

Kind regards,

nedvin
|||

I can see [Summary P&L] under the Account dimension. I use the enterprise edition version of the Adventure Works cube project. Make sure that you see the whole cube and not only a perspective("Show related fields to" at the top of the dimension tool)

HTH

Thomas Ivarsson

|||
Hi Thomas,

thank you for your reply.
I am using the Aventure Works cube project entreprise edition as well.In Excel 2007 the dropdown list 'Show fields related to' is set to the property 'All', so I think that I am not restricted to a perspective.
I can browse the cube in the SQL Server Management Studio(as well as in the BI Development Studio) and see the named sets as defined, but with Excel 2007 the named sets are not listed (neither the [Summary P&L] under the Account dimension nor the folder 'Sets' with 'Core Product Group', 'Long Lead Products',.... under the Product dimension).
By the way, I have Excel 2007 (12.0.6024.5000) MSO(12.0.6017.5000). Maybe I have a different version of Excel 2007?

Kind regards,
nedvin

Can''t see named sets in Excel 2007

Hi there,

I am not able to see the named sets in the PivotTable Field List in Excel 2007. I created e.g. the simple named set

CREATE SET CURRENTCUBE.[Austria]
AS [CUSTOMER].[COUNTRY].&[Austria] ;

Then I changed the display folder to 'Special Countries' in the mask 'Calculation properties' without selecting an 'Associated Measure Group'. After building the cube I can even see that display folder in the left-side tree of the 'Browse' window.
But after connecting to the cube with Excel 2007 the named set is not available for selection.

It seems that I am missing an important point.

Best wishes from Austria,

nedvin

I'm using Excel 2007 against the Adventure Works DW database and the Adventure Works cube. In the Account dimension, I see the [Summary P&L] named set. It has a Display folder of Sets and an Associated Measure Group of Financial Reporting.

You may want to compare what you have to what is in Adventure Works.

B.

|||Hi Bryan,

it took some time to install the Adventure Works Cube (actually I have completely reinstalled my pc), sorry for the late reply.
But even with your example I am unable to find the named set in the PivotTable Field List in Excel 2007. There is simply no folder 'Sets' containing the named set [Summary P&L].
I do see the [Summary P&L] in the cube (in the specified folder) and it is well defined under the mask 'Calculation properties', but in Excel 2007 it is not listed.

Kind regards,

nedvin
|||

I can see [Summary P&L] under the Account dimension. I use the enterprise edition version of the Adventure Works cube project. Make sure that you see the whole cube and not only a perspective("Show related fields to" at the top of the dimension tool)

HTH

Thomas Ivarsson

|||
Hi Thomas,

thank you for your reply.
I am using the Aventure Works cube project entreprise edition as well.In Excel 2007 the dropdown list 'Show fields related to' is set to the property 'All', so I think that I am not restricted to a perspective.
I can browse the cube in the SQL Server Management Studio(as well as in the BI Development Studio) and see the named sets as defined, but with Excel 2007 the named sets are not listed (neither the [Summary P&L] under the Account dimension nor the folder 'Sets' with 'Core Product Group', 'Long Lead Products',.... under the Product dimension).
By the way, I have Excel 2007 (12.0.6024.5000) MSO(12.0.6017.5000). Maybe I have a different version of Excel 2007?

Kind regards,
nedvin
sql

Can''t see named sets in Excel 2007

Hi there,

I am not able to see the named sets in the PivotTable Field List in Excel 2007. I created e.g. the simple named set

CREATE SET CURRENTCUBE.[Austria]
AS [CUSTOMER].[COUNTRY].&[Austria] ;

Then I changed the display folder to 'Special Countries' in the mask 'Calculation properties' without selecting an 'Associated Measure Group'. After building the cube I can even see that display folder in the left-side tree of the 'Browse' window.
But after connecting to the cube with Excel 2007 the named set is not available for selection.

It seems that I am missing an important point.

Best wishes from Austria,

nedvin

I'm using Excel 2007 against the Adventure Works DW database and the Adventure Works cube. In the Account dimension, I see the [Summary P&L] named set. It has a Display folder of Sets and an Associated Measure Group of Financial Reporting.

You may want to compare what you have to what is in Adventure Works.

B.

|||Hi Bryan,

it took some time to install the Adventure Works Cube (actually I have completely reinstalled my pc), sorry for the late reply.
But even with your example I am unable to find the named set in the PivotTable Field List in Excel 2007. There is simply no folder 'Sets' containing the named set [Summary P&L].
I do see the [Summary P&L] in the cube (in the specified folder) and it is well defined under the mask 'Calculation properties', but in Excel 2007 it is not listed.

Kind regards,

nedvin
|||

I can see [Summary P&L] under the Account dimension. I use the enterprise edition version of the Adventure Works cube project. Make sure that you see the whole cube and not only a perspective("Show related fields to" at the top of the dimension tool)

HTH

Thomas Ivarsson

|||
Hi Thomas,

thank you for your reply.
I am using the Aventure Works cube project entreprise edition as well.In Excel 2007 the dropdown list 'Show fields related to' is set to the property 'All', so I think that I am not restricted to a perspective.
I can browse the cube in the SQL Server Management Studio(as well as in the BI Development Studio) and see the named sets as defined, but with Excel 2007 the named sets are not listed (neither the [Summary P&L] under the Account dimension nor the folder 'Sets' with 'Core Product Group', 'Long Lead Products',.... under the Product dimension).
By the way, I have Excel 2007 (12.0.6024.5000) MSO(12.0.6017.5000). Maybe I have a different version of Excel 2007?

Kind regards,
nedvin

Can''t see named sets in Excel 2007

Hi there,

I am not able to see the named sets in the PivotTable Field List in Excel 2007. I created e.g. the simple named set

CREATE SET CURRENTCUBE.[Austria]
AS [CUSTOMER].[COUNTRY].&[Austria] ;

Then I changed the display folder to 'Special Countries' in the mask 'Calculation properties' without selecting an 'Associated Measure Group'. After building the cube I can even see that display folder in the left-side tree of the 'Browse' window.
But after connecting to the cube with Excel 2007 the named set is not available for selection.

It seems that I am missing an important point.

Best wishes from Austria,

nedvin

I'm using Excel 2007 against the Adventure Works DW database and the Adventure Works cube. In the Account dimension, I see the [Summary P&L] named set. It has a Display folder of Sets and an Associated Measure Group of Financial Reporting.

You may want to compare what you have to what is in Adventure Works.

B.

|||Hi Bryan,

it took some time to install the Adventure Works Cube (actually I have completely reinstalled my pc), sorry for the late reply.
But even with your example I am unable to find the named set in the PivotTable Field List in Excel 2007. There is simply no folder 'Sets' containing the named set [Summary P&L].
I do see the [Summary P&L] in the cube (in the specified folder) and it is well defined under the mask 'Calculation properties', but in Excel 2007 it is not listed.

Kind regards,

nedvin
|||

I can see [Summary P&L] under the Account dimension. I use the enterprise edition version of the Adventure Works cube project. Make sure that you see the whole cube and not only a perspective("Show related fields to" at the top of the dimension tool)

HTH

Thomas Ivarsson

|||
Hi Thomas,

thank you for your reply.
I am using the Aventure Works cube project entreprise edition as well.In Excel 2007 the dropdown list 'Show fields related to' is set to the property 'All', so I think that I am not restricted to a perspective.
I can browse the cube in the SQL Server Management Studio(as well as in the BI Development Studio) and see the named sets as defined, but with Excel 2007 the named sets are not listed (neither the [Summary P&L] under the Account dimension nor the folder 'Sets' with 'Core Product Group', 'Long Lead Products',.... under the Product dimension).
By the way, I have Excel 2007 (12.0.6024.5000) MSO(12.0.6017.5000). Maybe I have a different version of Excel 2007?

Kind regards,
nedvin

Saturday, February 25, 2012

can't pick up the RIGHT most character

Hi,
I have a bit of code which I need to take the last character of a field and
place it at the end of the output. (Sorry if the English does not make much
sense – let me explain further)
The first bit of code is fine:
SELECT U_hvdfinal.*
INTO U_T_STEP03F
FROM U_hvdfinal
WHERE U_hvdfinal.hvd IN ('HVDDA1', 'HVDDA2', 'HVDDA3')
It will then create a table with:
123456789 HVDDA2
214567894 HVDDA1
etc
etc
I then wish to add this to an existing table to appear similar to:
Refhvd
123456789 3F-HVDDA -2
214567894 3F-HVDDA -1
depending on what the last character of the hvd field has in it. So if the
field is HVDDA1 then it should endup looking like: 3F-HVDDA-1. However, using
the sql shown below I am coming up with 3F-HVDDA –
UPDATE U_segment
SET SEGMENT = '3F-' + LEFT(U_T_STEP03F.hvd, 5) + ' - ' + +
RIGHT(U_T_STEP03F.hvd, 1)
FROM U_segment
INNER JOIN U_T_STEP03F
ON U_segment.REF = U_T_STEP03F.REF
WHERE U_segment.SEGMENT IS NULL
What am I doing wrong? I have tried a couple of combinations but it’s still
coming up with the same result?
Thanks in advance
Rob
It may be that the last character is not what you think and might be a
space. Try RIGHT(RTRIM(U_T_STEP03F.hvd), 1)
"Robert" <Robert@.discussions.microsoft.com> wrote in message
news:03C5168A-5396-481F-BA2F-12EF07046240@.microsoft.com...
> Hi,
> I have a bit of code which I need to take the last character of a field
> and
> place it at the end of the output. (Sorry if the English does not make
> much
> sense - let me explain further)
> The first bit of code is fine:
> SELECT U_hvdfinal.*
> INTO U_T_STEP03F
> FROM U_hvdfinal
> WHERE U_hvdfinal.hvd IN ('HVDDA1', 'HVDDA2', 'HVDDA3')
>
> It will then create a table with:
> 123456789 HVDDA2
> 214567894 HVDDA1
> etc
> etc
> I then wish to add this to an existing table to appear similar to:
> Ref hvd
> 123456789 3F-HVDDA -2
> 214567894 3F-HVDDA -1
> depending on what the last character of the hvd field has in it. So if the
> field is HVDDA1 then it should endup looking like: 3F-HVDDA-1. However,
> using
> the sql shown below I am coming up with 3F-HVDDA -
>
> UPDATE U_segment
> SET SEGMENT = '3F-' + LEFT(U_T_STEP03F.hvd, 5) + ' - ' + +
> RIGHT(U_T_STEP03F.hvd, 1)
> FROM U_segment
> INNER JOIN U_T_STEP03F
> ON U_segment.REF = U_T_STEP03F.REF
> WHERE U_segment.SEGMENT IS NULL
> What am I doing wrong? I have tried a couple of combinations but it's
> still
> coming up with the same result?
> Thanks in advance
> Rob
>
|||Or perhaps your SEGMENT column is not wide enough to hold the longer value.
It may be truncating the final character.
Thanks,
Don
"Nik Marshall-Blank" wrote:

> It may be that the last character is not what you think and might be a
> space. Try RIGHT(RTRIM(U_T_STEP03F.hvd), 1)
> "Robert" <Robert@.discussions.microsoft.com> wrote in message
> news:03C5168A-5396-481F-BA2F-12EF07046240@.microsoft.com...
>
>

Friday, February 24, 2012

can't modify table in SMS...timeout expired?

Hi: I'm trying to add a field to a table by modifying it in Management
Studio. I'm running SQLSMS locally on the server.
When I try to save the table I get an error
"Post-Save Notifications...
[table name]
- Unable to modify table.
Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding."
The table currently has 5454 rows in it.
geek-y-guy (noone@.nowhere.org) writes:
> Hi: I'm trying to add a field to a table by modifying it in Management
> Studio. I'm running SQLSMS locally on the server.
That is a very dangerous function, which has serious bugs and shortcomings.
I strongly recommend to use ALTER TABLE statements to change your tables.
Or, at the very least, never, I say NEVER, save directly to implement
a change, but always generate a script and perform these modifications:
o Remove all BEGIN and COMMIT TRANSACTION except for the first and last.
o Wrap all batches in IF @.@.trancount > 0 BEGIN ... END
o Change all WITH NOCHECK to WITH CHECK.
And be very careful to check that the script only include the
changes you want to make. There are bugs that can cause discarded
changes to be includd.

> When I try to save the table I get an error
> "Post-Save Notifications...
> [table name]
> - Unable to modify table.
> Timeout expired. The timeout period elapsed prior to completion of the
> operation or the server is not responding."
> The table currently has 5454 rows in it.
Under Tools->Options there is a timeout for the Designers you can
change, if you insist on using that function. But if you run the script
from a query window,the timeout is not an issue.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Sunday, February 12, 2012

Cant insert the value NULL into column

I'm trying to modify the data type in a field on a table. I rec'd this message:
Unable to modify tblship_sched
Can't insert the value NULL into column mfg_qty table qc.dbo.Tmp_tblship_sched; Column doesn't allow nulls.
Insert fails.

What is or where is the Tmp table?

Thank you.I am not sure what you mean when you ask where the table is.

SELECT * FROM SYSOBJECTS WHERE NAME = 'Tmp_tblship_sched'

If the table exists then I suggest you check the column constraint for the table in question. Looks like it has a NOT NULL constraint.

You can disable it for your insert.

Good Luck!

Cant insert NULL to DateTime field

Hi I'm using DetailView and I have a text box which show the date. I have formated the date as shortDate {0:d} format. I want to insert/update null if that text box is empty.

I have tried putting null value in my Update statement in sqlDataSource. And I'm getting error saying can't convert varchar to smalldatetime.

If I don't set null value as above, some large date (01/01/2033) has been inserted in my database.

Can anyone help me?

Moe

insert DBNull.Value not "null"

Hope this help|||Thanks a lot.. :)|||Dear,Can you explain where I put this code? I am newbie and have the same with formview, and I wonder where to enter this DBNULL?Can you help please?|||

Here is sample code:

sqlStmt ="insert into Emp (FirstName,LastName,Date) Values (?,?,?) ";conString ="Provider=sqloledb.1;user id=sa;pwd=;database=northwind;data source=localhost";cn =new OleDbConnection(conString);cmd =new OleDbCommand(sqlStmt, cn) ;cmd.Parameters.Add(new OleDbParameter("@.FirstName", OleDbType.VarChar, 40));cmd.Parameters.Add(new OleDbParameter("@.LastName", OleDbType.VarChar, 40));cmd.Parameters.Add(new OleDbParameter("@.Date", OleDbType.Date)); cmd.Parameters["@.FirstName"].Value = txtFirstName.Text;cmd.Parameters["@.LastName"].Value = txtLastName.Text;if ((txtDate.Text =="") ){cmd.Parameters["@.Date"].Value = DBNull.Value;}else{cmd.Parameters["@.Date"].Value = DateTime.Parse(txtDate.Text);}cn.Open();cmd.ExecuteNonQuery();Label1.Text ="Record Inserted Succesfully";

Can't group on Month part of the date.

Hi everyone,
I have a report with Period field that I use on a graph as Category
field (horozontal axe.) I want to group on the month part of the
Period. In my sql query Period is DATETIME. I found a similar topic
here and used this expession to group on month:
=DatePart("MM", Fields!Period.Value)
I also sorted by Period to preserve date-order.
I am getting the following error in preview:
The group expression for the grouping 'chart1_CategoryGroup1' contains
an error: Argument "Interval" is not a valid value.
Here is a format of my Period as it comes from SQL Server:
2004-02-29 00:00:00.000
Any ideas what is wrong?
Thanks in advance!
StanI just found my problem.
this
=DatePart("MM", Fields!Period.Value) shoild be like that:
=DatePart("M", Fields!Period.Value)
One single m!
Stan|||There is another problem. My data runs from February, 2004 to October,
2005. When I group on month my graph shows only 12 months. I don't see
data from the mid-end 2005!!! Is this s bug or a feature of RS'
Stan|||You need to group on the combination of year and month - otherwise data
from both Feb 2004 and Feb 2005 will be grouped together (and similarly
for other months, of course).
Something like =DatePart("yyyy", Fields!Period.Value) & " " &
DatePart("m", Fields!Period.Value)
You may need to convert this to a string, with a leading zero for the
month, for it to work correctly.|||Thanks! I did just that. In Group On expression for the Period in my
graph I entered:
=Year(Fields!Period.Value)*100 + Month(Fields!Period.Value)
so that I group on a combination of year and month.
Stan

Can't get unicode with ResultSet.getString()

Hi;
I am using MS Sql Server and it has an nvarchar field holding a name.
For ascii chars I get back the text in the database.
But if it is anything other than ascii, I get back a ? for each non
7-bit character. So a field with "a\u9f23b\u4011c" returns "a?b?c"
What do I need to set/do to get back the unicode values in the
database?
thanks - dave
david@.at-at-at@.windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
Page 2 Stage -- http://www.Page2Stage.com
Enemy Nations -- http://www.EnemyNations.com
me -- http://dave.thielen.com
Barbie Science Fair -- http://www.BarbieScienceFair.info
(yes I have lots of links)
Here is some code that illustrates the problem - all return a?b?c
package net.windward.store.util.test;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Properties;
import java.io.InputStream;
import java.io.Reader;
public class TestJdbcUnicode {
private static String className =
"com.microsoft.jdbc.sqlserver.SQLServerDriver" ;
private static String url =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=StoreTest";
private static String username = "sa";
private static String password = "mmouse";
public static void main(String[] args) throws Exception {
String textInDb = "a?b?c"; // was the actual text (not
\u)
System.out.println("text = " + textInDb);
displayString(textInDb);
textInDb = "a\u98a8b\u0436c";
System.out.println("text = " + textInDb);
displayString(textInDb); // only correct display
System.out.println("Standard open");
Class.forName(className).newInstance();
Connection conn = DriverManager.getConnection(url,
username, password);
Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from Person
where PersonId = 25325");
displayResult(rs);
byte [] data = new byte[10];
InputStream is = rs.getAsciiStream("name");
int len = is.read(data);
//obj = rs.getBytes("name");
Reader rdr = rs.getCharacterStream("name");
char [] cbuf = new char[10];
len = rdr.read(cbuf);
System.out.println("Properties open");
Class.forName(className).newInstance();
Properties info = new Properties();
info.put("user", username);
info.put("password", password);
conn = DriverManager.getConnection(url, info);
stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("select * from Person where
PersonId = 25325");
displayResult(rs);
System.out.println("Properties open UTF-8");
Class.forName(className).newInstance();
info = new Properties();
info.put("user", username);
info.put("password", password);
info.put("charSet", "UTF-8");
conn = DriverManager.getConnection(url, info);
stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("select * from Person where
PersonId = 25325");
displayResult(rs);
System.out.println("Properties open UTF-16");
Class.forName(className).newInstance();
info = new Properties();
info.put("user", username);
info.put("password", password);
info.put("charSet", "UTF-16");
conn = DriverManager.getConnection(url, info);
stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("select * from Person where
PersonId = 25325");
displayResult(rs);
System.out.println("Properties open unicode");
Class.forName(className).newInstance();
info = new Properties();
info.put("user", username);
info.put("password", password);
info.put("charSet", "unicode");
conn = DriverManager.getConnection(url, info);
stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("select * from Person where
PersonId = 25325");
displayResult(rs);
}
private static void displayResult(ResultSet rs) throws
Exception {
if (! rs.next()) {
System.err.println("No results");
return;
}
String rtn = rs.getString("name");
displayString(rtn);
}
private static void displayString(String rtn) {
System.out.println("rtn = " + rtn);
System.out.print("rtn[] = ");
for (int ind=0; ind<rtn.length(); ind++)
System.out.print("x" +
Integer.toHexString((int)rtn.charAt(ind)) + " ");
}
}
david@.at-at-at@.windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
Page 2 Stage -- http://www.Page2Stage.com
Enemy Nations -- http://www.EnemyNations.com
me -- http://dave.thielen.com
Barbie Science Fair -- http://www.BarbieScienceFair.info
(yes I have lots of links)
|||Yes this is a bug (I am assuming you are using the SQL Server 2005 JDBC
driver Beta2, perhaps not). We cut the getAsciiStream function we had a few
serious bugs in it that were not easy to resolve in a clear cut manner. The
JDBC spec is not super clear on how it is supposed to work.
For example, should getAsciiStream take the incoming TDS character data and
convert this to US-ASCII? What if the incoming data is in Japanese
collation and this is a lossy conversion, etc... there are lots of
situations where this could be lossy. Also, does it just mean send back the
raw bytes? Then why is it called Ascii Stream, etc... It makes my head
hurt bad when I am writing support for SQL Server's 1000+ TDS language
collations and I don't want to be lossy and corrupt customer data.
I think you can use getBytes to work around this for now, something like
this I believe ->
ByteArrayInputStream bas = new ByteArrayInputStream(rs.getBytes(2));
This might give you bytes in UNICODE that would necessitate you converting
to single byte stream, but this depends upon your back end collation. If
the collation is a simple 2:1 UNICODE -> Single Byte mapping then it is easy
to strip out every other byte.
You can do things like this as well:
InputStreamReader isr = new InputStreamReader(new
ByteArrayInputStream(rs.getBytes(2)), "US-ASCII");
Twiggle around with the "US-ASCII", maybe you want to convert using some
other encoding like UTF-8, etc...
Let me know which driver you are using and perhaps I can come up with a
better solution.
Also, I would like to hear your reasoning behind using getAsciiStream, why
do you find you need to use this API, let me know about this, this would be
good feedback for our team working on the SQL JDB 2005 driver.
Matt Neerincx [MSFT]
This posting is provided "AS IS", with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
"David Thielen" <david@.windward.net> wrote in message
news:c1srh1te9er4nh0h089oagua0frhgupuhm@.4ax.com...
> Here is some code that illustrates the problem - all return a?b?c
> package net.windward.store.util.test;
> import java.sql.DriverManager;
> import java.sql.Connection;
> import java.sql.Statement;
> import java.sql.ResultSet;
> import java.util.Properties;
> import java.io.InputStream;
> import java.io.Reader;
> public class TestJdbcUnicode {
> private static String className =
> "com.microsoft.jdbc.sqlserver.SQLServerDriver" ;
> private static String url =
> "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=StoreTest";
> private static String username = "sa";
> private static String password = "mmouse";
> public static void main(String[] args) throws Exception {
> String textInDb = "a?b?c"; // was the actual text (not
> \u)
> System.out.println("text = " + textInDb);
> displayString(textInDb);
> textInDb = "a\u98a8b\u0436c";
> System.out.println("text = " + textInDb);
> displayString(textInDb); // only correct display
> System.out.println("Standard open");
> Class.forName(className).newInstance();
> Connection conn = DriverManager.getConnection(url,
> username, password);
> Statement stmt =
> conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
> ResultSet.CONCUR_UPDATABLE);
> ResultSet rs = stmt.executeQuery("select * from Person
> where PersonId = 25325");
> displayResult(rs);
> byte [] data = new byte[10];
> InputStream is = rs.getAsciiStream("name");
> int len = is.read(data);
> // obj = rs.getBytes("name");
> Reader rdr = rs.getCharacterStream("name");
> char [] cbuf = new char[10];
> len = rdr.read(cbuf);
>
> System.out.println("Properties open");
> Class.forName(className).newInstance();
> Properties info = new Properties();
> info.put("user", username);
> info.put("password", password);
> conn = DriverManager.getConnection(url, info);
> stmt =
> conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
> ResultSet.CONCUR_UPDATABLE);
> rs = stmt.executeQuery("select * from Person where
> PersonId = 25325");
> displayResult(rs);
>
> System.out.println("Properties open UTF-8");
> Class.forName(className).newInstance();
> info = new Properties();
> info.put("user", username);
> info.put("password", password);
> info.put("charSet", "UTF-8");
> conn = DriverManager.getConnection(url, info);
> stmt =
> conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
> ResultSet.CONCUR_UPDATABLE);
> rs = stmt.executeQuery("select * from Person where
> PersonId = 25325");
> displayResult(rs);
>
> System.out.println("Properties open UTF-16");
> Class.forName(className).newInstance();
> info = new Properties();
> info.put("user", username);
> info.put("password", password);
> info.put("charSet", "UTF-16");
> conn = DriverManager.getConnection(url, info);
> stmt =
> conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
> ResultSet.CONCUR_UPDATABLE);
> rs = stmt.executeQuery("select * from Person where
> PersonId = 25325");
> displayResult(rs);
>
> System.out.println("Properties open unicode");
> Class.forName(className).newInstance();
> info = new Properties();
> info.put("user", username);
> info.put("password", password);
> info.put("charSet", "unicode");
> conn = DriverManager.getConnection(url, info);
> stmt =
> conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
> ResultSet.CONCUR_UPDATABLE);
> rs = stmt.executeQuery("select * from Person where
> PersonId = 25325");
> displayResult(rs);
> }
> private static void displayResult(ResultSet rs) throws
> Exception {
> if (! rs.next()) {
> System.err.println("No results");
> return;
> }
> String rtn = rs.getString("name");
> displayString(rtn);
> }
> private static void displayString(String rtn) {
> System.out.println("rtn = " + rtn);
> System.out.print("rtn[] = ");
> for (int ind=0; ind<rtn.length(); ind++)
> System.out.print("x" +
> Integer.toHexString((int)rtn.charAt(ind)) + " ");
> }
> }
>
> david@.at-at-at@.windward.dot.dot.net
> Windward Reports -- http://www.WindwardReports.com
> Page 2 Stage -- http://www.Page2Stage.com
> Enemy Nations -- http://www.EnemyNations.com
> me -- http://dave.thielen.com
> Barbie Science Fair -- http://www.BarbieScienceFair.info
> (yes I have lots of links)

Friday, February 10, 2012

Cant get recordID from Database Table

Hi

I have the same problem but those posts are no longer there. Are you able to help me out?

I couldn't work it out so I created a date/time field called StartDate for when each record is entered. I was trying to use that to grab the particular eventID.

Dim EventID =""

tbEventIDTest.Text =""

Dim EventDataSource1AsNew SqlDataSource()

EventDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString

EventDataSource1.SelectCommandType = SqlDataSourceCommandType.Text

EventDataSource1.SelectCommand ="SELECT EventID FROM Event "WHERE ([StartDate] = @.StartDate)"

EventID = EventDataSource1.SelectParameters.Item(EventID)

tbEventIDTest.Text = EventID

Thanks, any help will be appreciated.

Hi,

Try following

EventID = EventDataSource1.SelectParameters.Item(EventID).DefaultValue

Swati

|||

Hi and thanks for your help.

I tried it but it didn't work. DefaultVAlue wasn't even one of the default options. There was 'equals', 'GetHash', 'GetType', 'ReferenceEquals', 'To String'.

I was thinking that maybe my StartDate in the label and my StartDate in the database don't match. I might try adding a default value to test.

But I don't think that that is the problem.

Do you have any other ideas?

|||So you just want to get the EventID from the sqldataource, right? If so you can try:

Dim dssa As ?new DataSourceSelectArguments()

Dim dt As new DataTable
dt= ((DataView)EventDataSource1.Select(dssa)).ToTable()

EventID= dt.Rows(0)(0).ToString()

If?you just want to retrieve a single value, it's more easier to use SqlCommand:

Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString())

Dim cmd As New SqlCommand( "SELECT EventID FROM Event WHERE ([StartDate] = @.StartDate)", conn)

conn.Open()
EventID= cmd.ExecuteScalar()|||

Hi

I have entered in all of the code but it is asking me to declear 'DataView'. I have tried 'Integer' and 'String' but it doesn't like these. Can you help me out with this?

Cheers

George

|||

I've been experimenting. DataView is now and the site loads but now I get an error that says..........

Index was outside the bounds of the array.

Here is my code:

Dim EventDataSource1AsNew SqlDataSource()

EventDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString

Dim dssaAsNew DataSourceSelectArguments()

Dim EventIDAsString =""

Dim DataView =""

Dim dtAsNew Data.DataTable

dt = ((DataView)(EventDataSource1.Select(dssa))).ToTable()

EventID = dt.Rows(0)(0).ToString()

Dim connAsNew Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString())

Dim cmdAsNew Data.SqlClient.SqlCommand("SELECT EventID FROM Event WHERE ([StartDate] = @.StartDate)", conn)

conn.Open()

EventID = cmd.ExecuteScalar()

thanks

George

|||Hi George, it seems you forget to set SelectCommand for EventDataSource1, so no row returned by the Select methodSmile|||

Sorry about this but I still get the same error. Can you help me further, please?

The error says: Index was outside the bounds of the array.

For this line of code: dt = ((DataView)(RaffleDataSource1.Select(dssa))).ToTable()

Here is my whole code:

Dim EventDataSource1AsNew SqlDataSource()

EventDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString

Dim dssaAsNew DataSourceSelectArguments()

Dim EventIDAsString =""

Dim DataView =""

Dim dtAsNew Data.DataTable

dt = ((DataView)(EventDataSource1.Select(dssa))).ToTable()

EventID = dt.Rows(0)(0).ToString()

Dim connAsNew Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString())

Dim cmdAsNew Data.SqlClient.SqlCommand("SELECT EventID FROM Event WHERE ([StartDate] = @.StartDate)", conn)

EventDataSource1.SelectCommand = ("SELECT EventID FROM Event WHERE ([StartDate] = @.StartDate)")

conn.Open()

EventDataSource1.SelectCommand.ToString(EventID)

EventID = cmd.ExecuteScalar()

tbEventIDTest.Text = EventID

|||Try to set SelectCommand for?EventDataSource1?before?calling?EventDataSource1.Select(dssa)Smile:

==============Code==============
Dim EventDataSource1 As New SqlDataSource()

EventDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString

Dim dssa As New DataSourceSelectArguments()

Dim EventID As String = ""

Dim DataView = ""

Dim dt As New Data.DataTable

Dim conn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString())

Dim cmd As New Data.SqlClient.SqlCommand("SELECT EventID FROM Event WHERE ([StartDate] = @.StartDate)", conn)

EventDataSource1.SelectCommand = ("SELECT EventID FROM Event WHERE ([StartDate] = @.StartDate)")

conn.Open()

dt = ((DataView)(EventDataSource1.Select(dssa))).ToTable()

EventID = dt.Rows(0)(0).ToString()

'EventDataSource1.SelectCommand.ToString(EventID)

EventDataSource1.SelectParameters.Add("@.StartDate",StartDate)
' StartDate is a variable which will be passed as parameter for the SqlCommand

EventID = cmd.ExecuteScalar()

tbEventIDTest.Text = EventID
==============================

Note in the code above the EventID has been assigned?with?same?value twice, you can just use one of the 2 methods?(SqlCommand?or?SqlDataSource) to set it.

For more information, you can refer to:
Using Parameters with the SqlDataSource Control|||Thank you for the help and thank you for breaking it down fo me.

Cant get proper Field size using Enterprise Manager

This is frustrating. Im new at MS SQL and have created a table using Enterprise Manager. I need one of the fields to hold a paragraph or page of text... Ive tried every data type and even those with max length of 8000 or greater, I cannot get it to save more than the first 256 characters. I use an "INSERT" or "UPDATE" command from a PHP script on the front end...

any help would be amazing!

thank you!

michael wolffhave you thought that perhaps it is php that is not letting your text be longer then 256??

if you are using sql to insert the record get php to print out the sql that it is sending to the server and then see what happens if you execute that in the query analyzer|||Originally posted by rokslide
have you thought that perhaps it is php that is not letting your text be longer then 256??

if you are using sql to insert the record get php to print out the sql that it is sending to the server and then see what happens if you execute that in the query analyzer

the php shows the field as it should be... then i execute the INSERT... then missing text!|||have you actually tried executing the sql in the query analyzer?

I have been doing web based updates to sql for ages and I have only experienced this problem when I had stuffed up the command somewhere.|||you mean running the insert directly in EM to see if it takes the field size?

no, but ill try it now!|||i tried it and got this:

*********
Server: Msg 103, Level 15, State 7, Line 1
The identifier that starts with 'IN CASE YOU WERE WONDERING!! We've had some problems with our host and are currently working on fixing the problems this has cau' is too long. Maximum length is 128.
Server: Msg 128, Level 15, State 1, Line 1
The name 'IN CASE YOU WERE WONDERING!! We've had some problems with our host and are currently working on fixing the problems this has cau' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
************

its a 'VARCHAR' field of max length 8000... whys it telling me the max is 128 here? and whats it mean by "The nam"? its just text...

*****

heres the statement i ran:

INSERT INTO headlines VALUES (getdate(),"IN CASE YOU WERE WONDERING!! We've had some problems with our host and are currently working on fixing the problems this has caused with the site. Just getting tour dates updated, BIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXT 25 BIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXT 50 BIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXTBIG TEXT 100",25)

field types are: datetime, varchar, numeric...

and ideas?

thank you.

michael wolff|||okie, well that error message is not coming from MS SQL. MS SQL would say something like - Action aborted. String or Binary data would have been truncated - or some such...

can't remember the exact syntax...

so something else is saying that the field is 128/256.

in your php do you define the fields that you are putting data into? do they have default values for things like length??

I have passed the error to a friend that uses php and will pass on what he says.|||dont need to define the fields... well, its just a 'textarea' html field... and that value is passed into the 'INSERT' command...

the errors i posted above i got directly from the Query Analyzer... so i dont know...

please let me know what your friend says!

thank you

michael wolff|||Hi Michael,

I wonder if it's not just a problem with your double quotes around the string.
Could you try it with 'single quotes' (apostrophes?).
SQL thinks you refer to a column or other database name if you put it within double quotes.

Cheers,
Robert|||still cut it off at 254 characters..... and this is directly with the QA... so its the same results as doing it from a PHP script...|||Can you provide me with the script to create the table and the insert statement you're using and I'll take a look for you ?

Thanks
Mark|||i created the table directly in EM...

but heres the INSERT code, pretty straighforward:

$query="INSERT INTO headlines VALUES (getdate(),\"$newheadline\",\"$theid\")";|||Originally posted by celloshred
i created the table directly in EM...

You could right click the table in EM and choose All tasks->Generate SQL Scripts to get the script that would help us track down the problem.

I guess this is not the case, but there was a limit in old ODBC drivers which cut off chars/varchars at 256 characters.|||you got there just before me :-)|||not sure what that is, but heres the file (attached)|||Its the double quotes around the inserted string. Use single quotes.
However as you have a single quote inside the string you provided, additional quotes will need to surround those quotes.

Or you could on use run via iSQL

SET quoted_identifier OFF

which will allow you to use the query just as you have it, ie with double quotes

Can't get more than first field to evaluate.

I am having trouble getting an

IMBogus1 -

Can you provide more details about your problem? I'm afraid you haven't given us enough information to even know what you were doing when you had problems.

thanks,

|||We are still waiting on information from you. If we don’t hear from you in the next seven days, we will delete the thread. We do this to keep the system full of useful information for customers searching for answers and focus expert attention on active unanswered questions.|||

The trouble I am having is doing an evaluation expression of multiple results and looking for the entire sum of the results in my evaluation expression. Instead it only returns the sum or count of the first result field and ignores all the other result fields.

Thanks,

Pete

|||

Pete -

I can't tell from your description whether you are having this issue with a feature of Team Edition for Database Professionals, or whether you're having some sort of general Visual Studio problem. Can you provide a little more background? What Visual Studio feature are you using when you encountering this problem? Is this something you are running in to while using the Database Unit Testing features?

|||i am working on sql reporting|||

Ah, okay. I've moved your thread to the SQL Server Reporting Services forum, where you can get a better response about SQL Server Reporting questions.