Showing posts with label analyzer. Show all posts
Showing posts with label analyzer. Show all posts

Tuesday, March 27, 2012

Create Table Script Incorrect syntax near 'Collate'

HI.

I am using SQL Server 2000. I generate a script of some table from EmpDB database when I run script in query analyzer it return error "Incorrect syntax near 'COLLATE'."

Scripts is

************************************************** ****
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Emp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Emp]
GO

CREATE TABLE [dbo].[Emp] (
[EmpID] [int] NOT NULL ,
[EmpName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

************************************************** ****
When I remove " COLLATE SQL_Latin1_General_CP1_CI_AS" from script manually then it run successfully.

Please guide why it is happening and how to escape from error.

Thanx in advance.I have tried your code and it works on my PC.

Try creating the table without the Collation and then use entreprice manager to assign the spicfic collation to the field. Does the specific calation exist?sql

Monday, March 19, 2012

create report incrementing date on left and results based on that date in subsequent

I would like to create a report in SQL Analyzer. Is there a For Next
construct or equivalent?
declare @.now datetime
set @.now = '2005-09-19 17:57:00.00'
for i = 1 to 60 -- pseudocode
select @.now
select count(Create_DT) from customer where EmailSent_DT > @.now and
EmailSent_IN = 1
select count(Create_DT) from customer where EmailSent_DT > @.now and
EmailSent_IN = 2
next
********** output results *****************
Col1 Col2
Col3
date Count(query result based on date)
Count(query result based on date)
date + 1 day Count(query result based on date + 1)
Count(query result based on date + 1 )
date + 2 day Count(query result based on date + 2)
Count(query result based on date + 2)
date + 3 day Count(query result based on date + 3)
Count(query result based on date + 3)
******************************
thank you - gregThere is a WHILE loop construct in SQL. However, for general application
related tasks, it is seldom needed. If you post your table structures,
sample schema & expected results ( www.aspfaq.com/5006 ) someone here can
perhaps show you how to generate the required resultset without iteration.
One general trick employed in SQL for such requirements is using a table of
sequentially incrementing numbers. You can find several solutions related to
this, if you search the archives of this newsgroup.
Anith|||Try using WHILE with a counter and then increment the counter in the code.
HTH
Jerry
"hazz" <hazz@.sonic_net> wrote in message
news:eMk64gN0FHA.2064@.TK2MSFTNGP09.phx.gbl...
>I would like to create a report in SQL Analyzer. Is there a For Next
>construct or equivalent?
> declare @.now datetime
> set @.now = '2005-09-19 17:57:00.00'
> for i = 1 to 60 -- pseudocode
> select @.now
> select count(Create_DT) from customer where EmailSent_DT > @.now and
> EmailSent_IN = 1
> select count(Create_DT) from customer where EmailSent_DT > @.now and
> EmailSent_IN = 2
> next
> ********** output results *****************
> Col1 Col2 Col3
> date Count(query result based on date) Count(query
> result based on date)
> date + 1 day Count(query result based on date + 1) Count(query
> result based on date + 1 )
> date + 2 day Count(query result based on date + 2) Count(query
> result based on date + 2)
> date + 3 day Count(query result based on date + 3) Count(query
> result based on date + 3)
> ******************************
> thank you - greg
>|||Beautiful. Thank you.
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:OgT8xoN0FHA.3904@.TK2MSFTNGP15.phx.gbl...
> Try using WHILE with a counter and then increment the counter in the code.
> HTH
> Jerry
> "hazz" <hazz@.sonic_net> wrote in message
> news:eMk64gN0FHA.2064@.TK2MSFTNGP09.phx.gbl...
>

Thursday, March 8, 2012

Create new Table from existing table

Hi

I'm trying to Create a new Table from existing table in Q/Analyzer. I figured it would be something like this:

CREATE TABLE newTable AS
(SELECT * FROM OldTable);

but i keep getting

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.

also.. is there another method of doing this, something like

INSERT INTO newTable
(SELECT * FROM OldTable);

and it creates the table ( newTable ) for u if it doenst already exist??

Cheers!!!

im using sql2000

You can try this one:

SELECT

* INTO newTableFROM OldTable|||

The easiest method to copy a table with data is :

SELECT * INTO MyNewTable FROM MyTable

Note: this method does not copy constraints and indexes.

|||

SELECT * INTO will create the table and also transfer the data. If you just want the table structure you can do

SELECT * INTO newTable FROM OldTable WHERE 1=0

You would need to add any constraints/indexes manually.

|||

Thanks for ya help fellas

all helpfull answers

Cheers!!!

Wednesday, March 7, 2012

create multiple views

Hi,
I want to create multiple views in one run in the query analyzer, but it
won't work. I've the following sqlcode in the analyzer:
create view test1 as select.......
create view test2 as select......
etc.
What is wrong with this code?
On Thu, 5 Aug 2004 08:09:02 -0700, Ezekil wrote:

>Hi,
>I want to create multiple views in one run in the query analyzer, but it
>won't work. I've the following sqlcode in the analyzer:
>create view test1 as select.......
>create view test2 as select......
>etc.
>What is wrong with this code?
Hi Ezekil,
The CREATE VIEW statement must be the first in a batch. So your code will
run if you add batch seperators:
create view test1 as select.......
GO
create view test2 as select......
GO
etc.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

create multiple views

Hi,
I want to create multiple views in one run in the query analyzer, but it
won't work. I've the following sqlcode in the analyzer:
create view test1 as select.......
create view test2 as select......
etc.
What is wrong with this code?On Thu, 5 Aug 2004 08:09:02 -0700, Ezekil wrote:

>Hi,
>I want to create multiple views in one run in the query analyzer, but it
>won't work. I've the following sqlcode in the analyzer:
>create view test1 as select.......
>create view test2 as select......
>etc.
>What is wrong with this code?
Hi Ezekil,
The CREATE VIEW statement must be the first in a batch. So your code will
run if you add batch seperators:
create view test1 as select.......
GO
create view test2 as select......
GO
etc.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)