Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Monday, March 12, 2012

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

Friday, March 9, 2012

How to set right utf-8 in sql server 2005 db?

Hello,

I try to insert some data in Vietnamese into sql server db from Sql server management studio express.

I enter an insert query with some unicode data like this 'm?t hai ba b?n n?m sáu b?y tám chín m??i', and I expect the db should contain the same text as above.

However, what I retrieved is 'm?t hai ba b?n nam sáu b?y tám chín mu?i'.

Can anyone help? Many thanks.

maivangho

Hi~ you may check you server's regional settings in control panel, and set all those to your language related, and check<globalization> section of config file.

If it still doesn't work, underSystem.Text there are some classes for encoding/decoding, you may try encode your data before putting them into DB... though this is not a good walkaround..

how to set null values to the database ?

I have some textboxes that could be blank when the form is submitted. If so, I want those fields in SQL database table to be set NULL when the insert is executed. I also need to convert the values in these textbexes to either INT or String if there are values there. I tried the following.

--Code

int RowNumber;

if (((TextBox)(e.Item.FindControl("RowNumber"))).Text != "" )
{
RowNumber = int.Parse(((TextBox)(e.Item.FindControl("RowNumber"))).Text);
}
else
{
RowNumber = DBNULL.value;
}

--Code

I got the error:

Cannot implicitly convert type "System.DBNull" to "int".

I want to pass RowNumber later to set NULL on the table. I know the data type is not correct, but how I get around with it ? and Is this the only problem ?

Thanks you very dmuchYou'll have to wait until you pass the value into the parameter itself to perform the test; once there, you can pass the parameter the value DBNull.Value.|||Thank you very much.. Can you show me how to do it.. please ?|||Assuming you are using sprocs, and passing in parameters to these sprocs:

'With your command object
myCmd.Parameters.Add("@.myParam",SQLDBType.INT).Value = IIf(myTextBox.Text <> "", myTextBox.Text, DBNull.Value)

Obviously, this is over-simplified (and in VB, no less), but I hope it gives you a general idea...|||I understand that I can do this when I put up the Sqlparameter object. But the problem is that I need to pass all the variables from my code-behind to a component which handles all the Sqlparameter things. It would not all me to pass the variables if they are not assigned certain values. so I need to assign NULL to some of them if they have no values. But I cannot do that .. any help ?|||The way I handle this is to pass a non-value to the component; for example, Integer.MinValue. The test for MinValue inside of your sub, and replace it with DBNull.Value.|||Thank you very much, I will try that...

Wednesday, March 7, 2012

How to set IDENTITY_INSERT to ON?

Hi,
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert explicit value
for identity column in table 'tblCustomers' when IDENTITY_INSERT is set to
OFF.
/checkout.asp, line 112
Is this a database setting error? Can anyone instruct us on how to set the
IDENTITY_INSERT to ON for the ID column in our table?
Thanks.
nath.
Hi,
thats a session thing, llok in the BOL for more information:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-e0a5e5c373ee.htm
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON |
OFF }
HTH, Jens Suessmeyer.
|||Hi,
thats a session thing, llok in the BOL for more information:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-e0a5e5c373ee.htm
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON |
OFF }
HTH, Jens Suessmeyer.
|||The BOL? :o(
Total newbie here Jens...hope you can bear with me! :o)
Where/What is the BOL?
Thanks
Nath.
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1141478203.215944.156110@.i40g2000cwc.googlegr oups.com...
> Hi,
> thats a session thing, llok in the BOL for more information:
>
> ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-e0a5e5c373ee.htm
>
> SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON |
> OFF }
>
> HTH, Jens Suessmeyer.
>
|||BOL is Books Online. The documentation that comes with SQL Server.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:Om%23WVY5PGHA.5592@.TK2MSFTNGP11.phx.gbl...
> The BOL? :o(
> Total newbie here Jens...hope you can bear with me! :o)
> Where/What is the BOL?
> Thanks
> Nath.
> "Jens" <Jens@.sqlserver2005.de> wrote in message
> news:1141478203.215944.156110@.i40g2000cwc.googlegr oups.com...
>
|||Hi,
Doh!
Nath.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OpLMjd5PGHA.5152@.TK2MSFTNGP10.phx.gbl...
> BOL is Books Online. The documentation that comes with SQL Server.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
> news:Om%23WVY5PGHA.5592@.TK2MSFTNGP11.phx.gbl...
>
|||Are you certain you want to set IDENTITY_INSERT ON? There are special
situations where you may need to turn on this option but in most cases you
want to omit the column from your insert statement so that SQL Server will
assign the value automatically.
Hope this helps.
Dan Guzman
SQL Server MVP
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:ONykDn4PGHA.2828@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
> [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert explicit
> value
> for identity column in table 'tblCustomers' when IDENTITY_INSERT is set to
> OFF.
> /checkout.asp, line 112
> Is this a database setting error? Can anyone instruct us on how to set
> the
> IDENTITY_INSERT to ON for the ID column in our table?
> Thanks.
> nath.
>

How to set IDENTITY_INSERT to ON?

Hi,
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert exp
licit value
for identity column in table 'tblCustomers' when IDENTITY_INSERT is set to
OFF.
/checkout.asp, line 112
Is this a database setting error? Can anyone instruct us on how to set the
IDENTITY_INSERT to ON for the ID column in our table?
Thanks.
nath.Hi,
thats a session thing, llok in the BOL for more information:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-
e0a5e5c373ee.htm
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table
3; ON |
OFF }
HTH, Jens Suessmeyer.|||Hi,
thats a session thing, llok in the BOL for more information:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-
e0a5e5c373ee.htm
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table
3; ON |
OFF }
HTH, Jens Suessmeyer.|||The BOL? :o(
Total newbie here Jens...hope you can bear with me! :o)
Where/What is the BOL?
Thanks
Nath.
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1141478203.215944.156110@.i40g2000cwc.googlegroups.com...
> Hi,
> thats a session thing, llok in the BOL for more information:
>
> ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b18
2-e0a5e5c373ee.htm
>
> SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table &#
123; ON |
> OFF }
>
> HTH, Jens Suessmeyer.
>|||BOL is Books Online. The documentation that comes with SQL Server.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:Om%23WVY5PGHA.5592@.TK2MSFTNGP11.phx.gbl...
> The BOL? :o(
> Total newbie here Jens...hope you can bear with me! :o)
> Where/What is the BOL?
> Thanks
> Nath.
> "Jens" <Jens@.sqlserver2005.de> wrote in message
> news:1141478203.215944.156110@.i40g2000cwc.googlegroups.com...
>|||Hi,
Doh!
Nath.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OpLMjd5PGHA.5152@.TK2MSFTNGP10.phx.gbl...
> BOL is Books Online. The documentation that comes with SQL Server.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
> news:Om%23WVY5PGHA.5592@.TK2MSFTNGP11.phx.gbl...
>|||Are you certain you want to set IDENTITY_INSERT ON? There are special
situations where you may need to turn on this option but in most cases you
want to omit the column from your insert statement so that SQL Server will
assign the value automatically.
Hope this helps.
Dan Guzman
SQL Server MVP
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:ONykDn4PGHA.2828@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
> [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert e
xplicit
> value
> for identity column in table 'tblCustomers' when IDENTITY_INSERT is set to
> OFF.
> /checkout.asp, line 112
> Is this a database setting error? Can anyone instruct us on how to set
> the
> IDENTITY_INSERT to ON for the ID column in our table?
> Thanks.
> nath.
>

How to set IDENTITY_INSERT to ON?

Hi,
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert explicit value
for identity column in table 'tblCustomers' when IDENTITY_INSERT is set to
OFF.
/checkout.asp, line 112
Is this a database setting error? Can anyone instruct us on how to set the
IDENTITY_INSERT to ON for the ID column in our table?
Thanks.
nath.Hi,
thats a session thing, llok in the BOL for more information:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-e0a5e5c373ee.htm
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON |
OFF }
HTH, Jens Suessmeyer.|||Hi,
thats a session thing, llok in the BOL for more information:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-e0a5e5c373ee.htm
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON |
OFF }
HTH, Jens Suessmeyer.|||The BOL? :o(
Total newbie here Jens...hope you can bear with me! :o)
Where/What is the BOL?
Thanks
Nath.
"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1141478203.215944.156110@.i40g2000cwc.googlegroups.com...
> Hi,
> thats a session thing, llok in the BOL for more information:
>
> ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-e0a5e5c373ee.htm
>
> SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON |
> OFF }
>
> HTH, Jens Suessmeyer.
>|||BOL is Books Online. The documentation that comes with SQL Server.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:Om%23WVY5PGHA.5592@.TK2MSFTNGP11.phx.gbl...
> The BOL? :o(
> Total newbie here Jens...hope you can bear with me! :o)
> Where/What is the BOL?
> Thanks
> Nath.
> "Jens" <Jens@.sqlserver2005.de> wrote in message
> news:1141478203.215944.156110@.i40g2000cwc.googlegroups.com...
>> Hi,
>> thats a session thing, llok in the BOL for more information:
>>
>> ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-e0a5e5c373ee.htm
>>
>> SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON |
>> OFF }
>>
>> HTH, Jens Suessmeyer.
>|||Hi,
Doh!
Nath.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OpLMjd5PGHA.5152@.TK2MSFTNGP10.phx.gbl...
> BOL is Books Online. The documentation that comes with SQL Server.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
> news:Om%23WVY5PGHA.5592@.TK2MSFTNGP11.phx.gbl...
>> The BOL? :o(
>> Total newbie here Jens...hope you can bear with me! :o)
>> Where/What is the BOL?
>> Thanks
>> Nath.
>> "Jens" <Jens@.sqlserver2005.de> wrote in message
>> news:1141478203.215944.156110@.i40g2000cwc.googlegroups.com...
>> Hi,
>> thats a session thing, llok in the BOL for more information:
>>
>> ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/a5dd49f2-45c7-44a8-b182-e0a5e5c373ee.htm
>>
>> SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON |
>> OFF }
>>
>> HTH, Jens Suessmeyer.
>>
>|||Are you certain you want to set IDENTITY_INSERT ON? There are special
situations where you may need to turn on this option but in most cases you
want to omit the column from your insert statement so that SQL Server will
assign the value automatically.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Nathon Jones" <sales@.NOSHPAMtradmusic.com> wrote in message
news:ONykDn4PGHA.2828@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
> [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert explicit
> value
> for identity column in table 'tblCustomers' when IDENTITY_INSERT is set to
> OFF.
> /checkout.asp, line 112
> Is this a database setting error? Can anyone instruct us on how to set
> the
> IDENTITY_INSERT to ON for the ID column in our table?
> Thanks.
> nath.
>

How to set douplicate id in sql server 2005?

Hi There,

Some one please help me to achieve this task.

I have task to join 2 tables and insert values.The table which i am inserting values has typeid column which is primary key column.I supposed to insert values except this column(TypeId).When i m trying insert values its throw an error saying

Error: Cannot insert the value NULL into column column does not allow nulls. INSERT fails.

Please let me know ther is a way to set duplicate id for this rows?

Thanks in advance.

Don't select the typeID column in your OLE DB destination.|||I don't understand; how is that a column is a PK but you don't want to insert any value on it? a PK has to have a value, right?|||

Rafael Salas wrote:

I don't understand; how is that a column is a PK but you don't want to insert any value on it? a PK has to have a value, right?

It could either be an identity, or he needs to assign a value to it.|||

Hi ,

Yes i want to assign a value automatically for the TypeId for inserting rows.

|||See if this helps you. Take a look at my post:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1211015&SiteID=1|||

Hi Phil,

Thanks for response.I have gone thru your post.Is there any tutorial or sample available for this?

|||

Tamizhan wrote:

Hi Phil,

Thanks for response.I have gone thru your post.Is there any tutorial or sample available for this?


I wrote one just for you... http://www.ssistalk.com/2007/02/20/generating-surrogate-keys/
Also, a more simplified version can be found at SQLIS.com. It does not start where the table left off. (It assumes starting at 1 always). http://www.sqlis.com/37.aspx
|||

Hi Phil,

I have gone thru your articles i got the ideas to do. But i am facing problem while using theis scripts.

i have no.of sql statements i have droped no.of execute sql tasks for each statements.Please find the below script,

select MaxKey = case
when TypeId is null then 0
else TypeId
end
from tblType

__

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain

Inherits UserComponent

Private NextKey As Int32 = 0

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

Dim MaximumKey As Int32 = Me.Variables.MaxKey ' Grab value of MaxKey which was passed in

' NextKey will always be zero when we start the package.

' This will set up the counter accordingly

If (NextKey = 0) Then

' Use MaximumKey +1 here because we already have data

' and we need to start with the next available key

NextKey = MaximumKey + 1

Else

' Use NextKey +1 here because we are now relying on

' our counter within this script task.

NextKey = NextKey + 1

End If

Row.TypeId = NextKey ' Assign NextKey to our ClientKey field on our data row

End Sub

End Class

I followe all your steps as mentioned.Please Advice me.

|||Does your query return more than one row? Notice that you aren't selecting the max(typeid) from the table, tblType.

select MaxKey = case
when TypeId is null then 0
else TypeId
end
from tblType|||

Hi Phil,

Yes you are right.It returns more than one row.Please advice how to achieve this?

Please correct the script if there is a problem.

Many thanks in advance.

|||

Tamizhan wrote:

Hi Phil,

Yes you are right.It returns more than one row.Please advice how to achieve this?

Please correct the script if there is a problem.

Many thanks in advance.

Change your query to select the max(typeid) from the table. Your query isn't the same as mine.

how to set default value for datetime column in sql mobile?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

I can repro the failure you are seeing. On Searching BOL for sql mobile, It says the following about the default definitions for columns.

DEFAULT Definitions

A column can have only one DEFAULT definition. This can contain constant values or constant functions.

You should post this to the SQL Server Everywhere/Mobile/CE Edition Technical Discussion forum.

Friday, February 24, 2012

How to set Concurrent execution of 2 insert statements

Hi,
I ahve the followign trigger. In this I want to set the 2 Insert statements
at the bottom, to execute concurrently. How can I do that?
CREATE TRIGGER [Identity_Trigger] ON dbo.WyethDataCard
FOR INSERT
AS
DECLARE @.CompOrderNo VarChar(30)
DECLARE @.Sno int
DECLARE @.EndUser varchar(25)
DECLARE @.ESN varchar(20)
DECLARE @.MinNo varchar(12)
SELECT @.Sno=SNo, @.EndUser=[End User], @.ESN=ESN , @.MinNo=MobileNo from
inserted --where CompanyORderNo is null
UPDATE WyethDataCard
SET CompanyORderNo= CONVERT(VARCHAR(15), 'TK-WT-VZ-'+RTRIM(SNo) )
SELECT @.CompOrderNo= CompanyORderNo from WyethDataCard
INSERT INTO OrderStatus ( Company_OrderNo,Status_ID,Created_Date,C
ompanySno
)
VALUES( @.CompOrderNo ,'25', GetDate(),@.Sno )
INSERT INTO EndUserChangeHistory
(MasterOrderNo,ESN,MinNo,EndUser,Modifie
dBy,ModifiedOn)
VALUES ( @.CompOrderNo,
@.ESN,
@.MinNo,
@.EndUser,
'Database Import / Manual Insert',
GetDate()
)
Is there some statement like CONCURRENT EXEC to achieve this?
Thanks
pmudWhy do you want to make them concurrent? Even if the machine has several pro
cessors, there's no
guarantee that this will happen at the same time. If you want both or nothin
g, you should have some
error handling in the trigger (see the articles on error handling at www.sommarsko
g.se).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"pmud" <pmud@.discussions.microsoft.com> wrote in message
news:8338600F-74B5-4742-85E6-62789BD55AFD@.microsoft.com...
> Hi,
> I ahve the followign trigger. In this I want to set the 2 Insert statement
s
> at the bottom, to execute concurrently. How can I do that?
> CREATE TRIGGER [Identity_Trigger] ON dbo.WyethDataCard
> FOR INSERT
> AS
> DECLARE @.CompOrderNo VarChar(30)
> DECLARE @.Sno int
> DECLARE @.EndUser varchar(25)
> DECLARE @.ESN varchar(20)
> DECLARE @.MinNo varchar(12)
> SELECT @.Sno=SNo, @.EndUser=[End User], @.ESN=ESN , @.MinNo=MobileNo from
> inserted --where CompanyORderNo is null
> UPDATE WyethDataCard
> SET CompanyORderNo= CONVERT(VARCHAR(15), 'TK-WT-VZ-'+RTRIM(SNo) )
> SELECT @.CompOrderNo= CompanyORderNo from WyethDataCard
> INSERT INTO OrderStatus ( Company_OrderNo,Status_ID,Created_Date,C
ompanyS
no)
> VALUES( @.CompOrderNo ,'25', GetDate(),@.Sno )
> INSERT INTO EndUserChangeHistory
> (MasterOrderNo,ESN,MinNo,EndUser,Modifie
dBy,ModifiedOn)
> VALUES ( @.CompOrderNo,
> @.ESN,
> @.MinNo,
> @.EndUser,
> 'Database Import / Manual Insert',
> GetDate()
> )
> Is there some statement like CONCURRENT EXEC to achieve this?
> Thanks
> --
> pmud|||Hi Tibor,
Actually, by concurrent execution, I meant parallel execution of the 2
statements. Is tehre any way I can set parallel execution fo teh 2 statement
s
rather than having one after the other?
Thanks
--
pmud
"Tibor Karaszi" wrote:

> Why do you want to make them concurrent? Even if the machine has several p
rocessors, there's no
> guarantee that this will happen at the same time. If you want both or noth
ing, you should have some
> error handling in the trigger (see the articles on error handling at www.sommars
kog.se).
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "pmud" <pmud@.discussions.microsoft.com> wrote in message
> news:8338600F-74B5-4742-85E6-62789BD55AFD@.microsoft.com...
>|||Do you mean that the inserts should be atomic or within a single
transaction?
If so, then refer to this document, specifically the section titled
"Database Transactions".
http://msdn.microsoft.com/library/d...ent.
asp
"pmud" <pmud@.discussions.microsoft.com> wrote in message
news:8338600F-74B5-4742-85E6-62789BD55AFD@.microsoft.com...
> Hi,
> I ahve the followign trigger. In this I want to set the 2 Insert
> statements
> at the bottom, to execute concurrently. How can I do that?
> CREATE TRIGGER [Identity_Trigger] ON dbo.WyethDataCard
> FOR INSERT
> AS
> DECLARE @.CompOrderNo VarChar(30)
> DECLARE @.Sno int
> DECLARE @.EndUser varchar(25)
> DECLARE @.ESN varchar(20)
> DECLARE @.MinNo varchar(12)
> SELECT @.Sno=SNo, @.EndUser=[End User], @.ESN=ESN , @.MinNo=MobileNo from
> inserted --where CompanyORderNo is null
> UPDATE WyethDataCard
> SET CompanyORderNo= CONVERT(VARCHAR(15), 'TK-WT-VZ-'+RTRIM(SNo) )
> SELECT @.CompOrderNo= CompanyORderNo from WyethDataCard
> INSERT INTO OrderStatus (
> Company_OrderNo,Status_ID,Created_Date,C
ompanySno)
> VALUES( @.CompOrderNo ,'25', GetDate(),@.Sno )
> INSERT INTO EndUserChangeHistory
> (MasterOrderNo,ESN,MinNo,EndUser,Modifie
dBy,ModifiedOn)
> VALUES ( @.CompOrderNo,
> @.ESN,
> @.MinNo,
> @.EndUser,
> 'Database Import / Manual Insert',
> GetDate()
> )
> Is there some statement like CONCURRENT EXEC to achieve this?
> Thanks
> --
> pmud|||no
why?
"pmud" <pmud@.discussions.microsoft.com> wrote in message
news:B0D56D29-D70C-4684-9F7F-0957CBFF6443@.microsoft.com...
> Hi Tibor,
> Actually, by concurrent execution, I meant parallel execution of the 2
> statements. Is tehre any way I can set parallel execution fo teh 2
> statements
> rather than having one after the other?
> Thanks
> --
> pmud
>
> "Tibor Karaszi" wrote:
>|||Is there any tutorial or book you rae aware which I can read to quickly come
up to speed with transctions and how they are implemeted?
Actually, I am aware of the basic concept of trnsctions but have never
implemeted them.
Do you have any suggestions for me to get up to speed Quickly?
Thanks
--
pmud
"JT" wrote:

> Do you mean that the inserts should be atomic or within a single
> transaction?
> If so, then refer to this document, specifically the section titled
> "Database Transactions".
> http://msdn.microsoft.com/library/d...en
t.asp
> "pmud" <pmud@.discussions.microsoft.com> wrote in message
> news:8338600F-74B5-4742-85E6-62789BD55AFD@.microsoft.com...
>
>|||You will not need a book to understand the concept of basic transactions.
Database transaction:
http://en.wikipedia.org/wiki/Database_transaction
BEGIN TRANSACTION
http://msdn2.microsoft.com/en-us/library/ms188929(SQL.90).aspx
COMMIT TRANSACTION
http://msdn2.microsoft.com/en-us/library/ms190295(SQL.90).aspx
ROLLBACK TRANSACTION
http://msdn2.microsoft.com/en-us/library/ms181299(SQL.90).aspx
The simplified sample below attempts to transfer a balance of $100 between 2
accounts. If all goes well, the transaction is committed (saved) and the
value of 1 is returned. If there is an error, then the transaction is rolled
back (cancelled), and a value of -1 or -2 is returned. By executing both
updates within a transactions, we insure that the work is either all saved
or all cancelled and the accounts are balanced.
begin transaction
update Accounts set balance = balance - 100 where acct_number = 4625
if @.@.error <> 0
begin
rollback transaction
return -1
end
update Accounts set balance = balance + 100 where acct_number = 4650
if @.@.error <> 0
begin
rollback transaction
return -2
end
commit transaction
return 1
"pmud" <pmud@.discussions.microsoft.com> wrote in message
news:33501F2A-06A5-4CA4-A15F-3D8987DE9C80@.microsoft.com...
> Is there any tutorial or book you rae aware which I can read to quickly
> come
> up to speed with transctions and how they are implemeted?
> Actually, I am aware of the basic concept of trnsctions but have never
> implemeted them.
> Do you have any suggestions for me to get up to speed Quickly?
> Thanks
> --
> pmud
>
> "JT" wrote:
>|||Thanks JT. That is definitely helpful. :)
--
pmud
"JT" wrote:

> You will not need a book to understand the concept of basic transactions.
> Database transaction:
> http://en.wikipedia.org/wiki/Database_transaction
> BEGIN TRANSACTION
> http://msdn2.microsoft.com/en-us/library/ms188929(SQL.90).aspx
> COMMIT TRANSACTION
> http://msdn2.microsoft.com/en-us/library/ms190295(SQL.90).aspx
> ROLLBACK TRANSACTION
> http://msdn2.microsoft.com/en-us/library/ms181299(SQL.90).aspx
> The simplified sample below attempts to transfer a balance of $100 between
2
> accounts. If all goes well, the transaction is committed (saved) and the
> value of 1 is returned. If there is an error, then the transaction is roll
ed
> back (cancelled), and a value of -1 or -2 is returned. By executing both
> updates within a transactions, we insure that the work is either all saved
> or all cancelled and the accounts are balanced.
> begin transaction
> update Accounts set balance = balance - 100 where acct_number = 4625
> if @.@.error <> 0
> begin
> rollback transaction
> return -1
> end
> update Accounts set balance = balance + 100 where acct_number = 4650
> if @.@.error <> 0
> begin
> rollback transaction
> return -2
> end
> commit transaction
> return 1
>
> "pmud" <pmud@.discussions.microsoft.com> wrote in message
> news:33501F2A-06A5-4CA4-A15F-3D8987DE9C80@.microsoft.com...
>
>|||pmud (pmud@.discussions.microsoft.com) writes:
> I ahve the followign trigger. In this I want to set the 2 Insert
> statements at the bottom, to execute concurrently. How can I do that?
You can't, and there would be no point with it.
On the other hand:

> SELECT @.Sno=SNo, @.EndUser=[End User], @.ESN=ESN , @.MinNo=MobileNo from
> inserted --where CompanyORderNo is null
This is not going to work out well. Triggers in SQL Server fires
once *per statement*, so the inserted table can hold many rows, which
your trigger fails to handle.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

How To Set a Variable During an Insert Into Select From

Hello.
I'm inserting rows into a table that I retrieve from another table.
There's a lot of data manipulation going on during this process.
For 10 columns in the Select From portion I'm using a CASE statement that
starts with CASE
WHEN Left(Discount_Specification, 2)= @.PF THEN etc.
END,
Instead of doing the "Left" 10 times (10 * 8 million rows in the "From"
table!) I though of setting a variable: Set @.MyVar =
Left(Discount_Specification, 2) and then
saying WHEN @.MyVar = @.PF etc.
I just don't know where in the logic to place this Set @.MyVar so it works
for each row that's inserted.
TIA,
RitaHard to say without DDL, but perhaps something like:
INSERT INTO ...
SELECT ds, ds + 'a', col2
FROM
(
SELECT LEFT(Discout_Specification, 2) AS ds, col2 FROM tbl
) AS t
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"RitaG" <RitaG@.discussions.microsoft.com> wrote in message
news:A07835AD-AAC2-4225-BA8C-FDA70C1C0631@.microsoft.com...
> Hello.
> I'm inserting rows into a table that I retrieve from another table.
> There's a lot of data manipulation going on during this process.
> For 10 columns in the Select From portion I'm using a CASE statement that
> starts with CASE
> WHEN Left(Discount_Specification, 2)= @.PF THEN etc.
> END,
> Instead of doing the "Left" 10 times (10 * 8 million rows in the "From"
> table!) I though of setting a variable: Set @.MyVar =
> Left(Discount_Specification, 2) and then
> saying WHEN @.MyVar = @.PF etc.
> I just don't know where in the logic to place this Set @.MyVar so it works
> for each row that's inserted.
> TIA,
> Rita
>|||Hi Tibor,
Thanks for your response.
I'm trying to figure out how to use it along with a CASE statement.
Here's my code:
INSERT INTO MyTable(
Col1,
Col2,
etc.)
SELECT
CASE
WHEN Left(SM.Discount_Specification, 2) IN (@.P, @.L) THEN
Something
ELSE 1
END,
CASE
WHEN Left(SM.Discount_Specification, 2) = @.K THEN
SomethingElse
ELSE 1
END,
Etc.
From MyTable
Thanks,
Rita
"Tibor Karaszi" wrote:

> Hard to say without DDL, but perhaps something like:
> INSERT INTO ...
> SELECT ds, ds + 'a', col2
> FROM
> (
> SELECT LEFT(Discout_Specification, 2) AS ds, col2 FROM tbl
> ) AS t
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "RitaG" <RitaG@.discussions.microsoft.com> wrote in message
> news:A07835AD-AAC2-4225-BA8C-FDA70C1C0631@.microsoft.com...
>|||Is this a "lazy programmer doesn't want to type all those keystrokes" issue
or something else? It is possible that "Left(SM.Discount_Specification, 2)"
indicates a schema issue. If so, you should consider a change to the schema
to unbind the two attributes currently stored in the Discount_Specification
column. This can be done permanently via the addition of another column
(and the movement of the associated information), via a view, or via a
computed column, via a udf, etc. You can also do this via a derived table
within this particular query.
insert ...
select case when derived_discount in (@.P, @.L) then x else y end,
...
from
(select Left(SM.Discount_Specification, 2) as derived_discount,
...
from MyTable ) as t1
where ...|||Hi Scott,
No, it's not a "lazy programmer"! :-)
I just thought there may be a more efficient way since I'm dealing with a
large volume of rows (up to 10 million).
Thanks for your reponse. That was what I was looking for.
Rita
"Scott Morris" wrote:

> Is this a "lazy programmer doesn't want to type all those keystrokes" issu
e
> or something else? It is possible that "Left(SM.Discount_Specification, 2
)"
> indicates a schema issue. If so, you should consider a change to the sche
ma
> to unbind the two attributes currently stored in the Discount_Specificatio
n
> column. This can be done permanently via the addition of another column
> (and the movement of the associated information), via a view, or via a
> computed column, via a udf, etc. You can also do this via a derived table
> within this particular query.
> insert ...
> select case when derived_discount in (@.P, @.L) then x else y end,
> ...
> from
> (select Left(SM.Discount_Specification, 2) as derived_discount,
> ...
> from MyTable ) as t1
> where ...
>
>

How to set a SP run at mid-night ?

(1)I need to insert the data from vfp into sql every mid-night .
I think I can use SP to process the inset statment .
However, How can I set it run at mid-night automically 'Take a look at sql job:
http://msdn.microsoft.com/library/e...tomate_7awj.asp
-oj
"Agnes" <agnes@.dynamictech.com.hk> wrote in message
news:%23evjgqtSFHA.3312@.TK2MSFTNGP12.phx.gbl...
> (1)I need to insert the data from vfp into sql every mid-night .
> I think I can use SP to process the inset statment .
> However, How can I set it run at mid-night automically '
>
>|||SQLAgent ?
Gopi
"Agnes" <agnes@.dynamictech.com.hk> wrote in message
news:%23evjgqtSFHA.3312@.TK2MSFTNGP12.phx.gbl...
> (1)I need to insert the data from vfp into sql every mid-night .
> I think I can use SP to process the inset statment .
> However, How can I set it run at mid-night automically '
>
>