Reference A Temporary ##global Table Of A Linked Server Using 4-parts Identifier

Oct 17, 2007

Is it possible to reference a temporary global tale (##table) of a linked server using the 4 parts "identifier": linkedserver.database.schema_name.##object_name ??
Thanks in advance for your help.

View 2 Replies


ADVERTISEMENT

SQL Server 2012 :: Creating And Dropping Global Temporary Table?

Apr 3, 2015

I want to create and drop the global temporary table in same statement.

I am using below command but I am getting below error

Msg 2714, Level 16, State 6, Line 11

There is already an object named '##Staging_Temp' in the database.

if object_id('Datastaging..##Staging_Temp') is not null
begin
drop table ##Staging_Temp
end
CREATE TABLE ##Staging_Temp(
[COL001] [varchar](4000) NULL,

[Code] ....

View 1 Replies View Related

Temporary Table And Multi-part Identifier

Mar 27, 2006

Hi,

I want to join a temporary table with a table in my stored procedure :

CREATE PROCEDURE sp_DeltaabgleichDarlehen
AS
BEGIN

SELECT Grundeinstellungen.Dat_Initialisierung, Grundeinstellungen.Dat_Jahresbeginn
INTO #temp_IniDatum
FROM Grundeinstellungen

INSERT INTO DeltaDarlStammdaten (Datum, Vertragsnummer)
SELECT ImpDarlStammdaten.Datum, ImpDarlStammdaten.Vertragsnummer
FROM ImpDarlStammdaten
WHERE ImpDarlStammdaten.Datum=#temp_IniDatum.Dat_Jahresbeginn

END
    

i get the error :

The multi-part identifier "#temp_IniDatum.Dat_Jahresbeginn" could not be boundfor example

What is the problem? and how can i solve this?

thank you

Jupp

View 4 Replies View Related

Global Temporary Table

Dec 23, 2006

Hi,
what im trying to do is to combine multiple SELECT staetment so that it could produce 1 dataset instead of 2(multiple). (fields and column are same, just different tblname). Okay, so im thinking of insert those into temp table.

1. select statement 1 > insert into #MyTemp
2. select statement 2 > i want to insert into #MyTemp too...

Problem is sql disallowed this. That's why im thinking of global temporary table, but dunno how to write tht :P.
Pliz help. Thanks in advance

View 7 Replies View Related

Global Temporary Table And SP

Jul 23, 2005

Hello all,I'm using SS2K on W2K.Brieffing: Many months ago, I created a stored procedure only used by thosewith admin rights in SS. Now, someone else (without admin rights) has to runit. I gave him rigth to execute the SP but, at the second and moreexecution, he got a error message concerning a temp table already existing(see further).The SP:------------------------------------------------------CREATE PROCEDURE MySP@Type INTDECLARE @strSQL AS VARCHAR(4000)IF EXISTS (SELECT table_name FROM tempdb.information_Schema.tables WHEREtable_name = '##MyTmpTable')DROP TABLE ##MyTmpTableSELECT @strSQL = 'SELECT MyField1, MyField2, MyField3 INTO ##MyTmpTable FROMMyTable'EXECUTE(@strSQL)IF @Type = 1SELECT MyField1FROM ##MyTmpTableELSE IF @Type = 2SELECT MyField2FROM ##MyTmpTableELSESELECT MyField3FROM ##MyTmpTableGO------------------------------------------------------The error I got on the second time the user run the sp is: "Table##MyTmpTable already exists." The front-end where this SP is run is A97.That's where I got this message. This SP looks like a simple SELECT queryfrom A97 users perspective.Please, do no argue about the way of doing the work done! It is simplifiedat most in order to make it short and easy to read. I have to use thecommand "EXECUTE(String)" and, because of this, I connot use a localtemporary table instead of a global one.I suspect non-admin user cannot drop global temporary table, but the errormessage makes me believe that this code line is not even run, as if thecondition "IF EXISTS(...)" return false even if the table actualy exists.Anybody can help about this? What should I do to solve this problem?Yannick

View 2 Replies View Related

Accessing Global Temporary Table

Jan 29, 2001

We are trying to use a ## table (global temporary table) in Access or Excel thru a ODBC connection to tempdb. We are able to see the system tables, but not any ## tables. We are able to perform selects on the same ## table with the same userid and password in Query Analyzer. If we use sa or make the userid dbo we are able to see the ## tables, but I don't want to give these type of permissions.

Any help would be appreciated. Thanks in advance.

View 1 Replies View Related

Global Temporary Table Usage In Sub Reports

Mar 28, 2008



Hi,

I have a report that calls a stored procedure that creates an extract of data for use by various subreports. Now I have this problem:

If I save the extract data in a global temporary table, then it is automatically deleted before the subreports can use it, this means I have to create a normal table with a unique name that need to be deleted - but where do you do this in the report - there is no point where you can say it is now safe to delete a table?

I do not want to resort to external mechanisms, languages, jobs etc. to do this. I want to delete the table once the report is really finished in the report.

My main report uses a list that contains all the subreports as I need to group all sorts of information by vendor. The main report calls the stored procedure. Please do not tell me that I have to duplicate the main extract for every subreport. That will really eat resources.

Thanks in advance.

View 4 Replies View Related

Global Temporary Table Usage In Subreports

Mar 28, 2008



Hi,

I have a report that calls a stored procedure that creates an extract of data for use by various subreports. Now I have this problem:

If I save the extract data in a global temporary table, then it is automatically deleted before the subreports can use it, this means I have to create a normal table with a unique name that need to be deleted - but where do you do this in the report - there is no point where you can say it is now safe to delete a table?

I do not want to resort to external mechanisms, languages, jobs etc. to do this. I want to delete the table once the report is really finished in the report.

My main report uses a list that contains all the subreports as I need to group all sorts of information by vendor. The main report calls the stored procedure. Please do not tell me that I have to duplicate the main extract for every subreport. That will really eat resources.

Thanks in advance.

View 6 Replies View Related

Transact SQL :: Temporary Table Created In Linked Server

Sep 20, 2015

I'm executing a sp name  [uspGeneral_Getinfo]. It return a global temporary table's name and I want to get data from that table.

[192.168.2.11] = Linked Server

Declare@LinkedServer varchar(40)='[192.168.2.11].DBPharm.dbo.',@OutPutTableName varchar(50)=' ',@SQL nvarchar(max)Set@LinkedServer=Rtrim(Ltrim(@LinkedServer))Set@SQL=' Declare @OutPutTableName varchar(50),@SQL nvarchar(max) EXEC '+@LinkedServer+'[uspGeneral_GetDomainDataNew] 9,null, @OutPutTableName OutPut '+' Set @SQL='''+'Select * from '''+'+ @OutPutTableName'+' Exec sp_executesql @SQL 'Select@SQL

Above code are executing from another server [192.168.2.10].But getting an error that .I can't able to search where the temp table created in linked serve tempdb or ...?

Database name 'tempdb' ignored, referencing object in tempdb.
Database name 'tempdb' ignored, referencing object in tempdb.
Database name 'tempdb' ignored, referencing object in tempdb.
Database name 'tempdb' ignored, referencing object in tempdb.
Msg 208, Level 16, State 0, Line 38
Invalid object name '##table1FD1B81Bx4EAFx4FFDx9F6Fx15B77B6445F'.

View 8 Replies View Related

Create Global Temporary Tables In SQL SERVER

Sep 6, 2006

I m trying to create a global temporary table whose data will be deleted after the end of the session..

the DDL in oracle is

CREATE GLOBAL TEMPORARY TABLE STUDENT
(

name CHAR(20),

) ON COMMIT DELETE ROWS ;

I want to know the corresponding DDL in SQL Server..

when i try the following

CREATE TABLE ##STUDENT
(

name CHAR(20),

)

the table gets deleted at the end of the session..help needed



View 4 Replies View Related

Executing A Sp Via ADO Which Makes A Reference To Linked Server Table Results In Error

Oct 17, 1999

Greetings,

Facing a strange problem, but obviously not expected earlier on, I am trying to execute a stored procedure via ADO which refrences a linked server table and I get an error specifying
"
OLEDB provider SQLOLEDB does not contain table "<DatabaseName>"."<owner>"."<tableName>"
"

Has any one else encountered this problem before ?
regards
Govind

View 1 Replies View Related

SQL Server 2012 :: Maximum Number Of Global Temporary Tables?

Dec 9, 2014

What is the maximum no.of global temporary tables can create in sql server

View 4 Replies View Related

Scripting Stored Procedure Add With Linked Server Reference When Linked Server Is Not Available

Jul 18, 2006

Is there a way to bypass the syntax checking when adding a stored procedure via a script?

I have a script that has a LINKed server reference (see below) .

INSERT
INTO ACTDMSLINKED.ACTDMS.DBO.COILS ..etc.

ACTDMSLINKED does not exist at the time I need to add the stored procedure that references it.

PLEASE to not tell me to add the LINK and then run the script. This is not an option in this scenerio.

Thanks,

Terry

View 4 Replies View Related

Storing GUID (global Unique Identifier)

Feb 9, 2005

Function GUID() As String
GUID = System.GUID.NewGuid().ToString()
End Function

GUID is always 36 characters, for example:

1737be72-fe96-4c3c-b455-3730b049bef9

What the best way to store this in a MS SQL database? I'm thinking of using a fixed length string (char). Is there a better way than to just store this 36 character field?

View 2 Replies View Related

T-SQL (SS2K8) :: CTE With Linked Server - Multipart Identifier Could Not Be Bound

Jul 17, 2014

Interesting issue. I have the following CTE that JOINs some tables from a Linked Server which is our SAP data. This CTE is in a stored procedure and then executed via a SQL Server Agent Job on a timer (every 10 minutes). This ran fine for almost 20 hours and then dies with a multipart identifier could not be bound error (exact error below CTE).

Server running the job: SQL Server 2008 R2 (no SP)

Linked Server: SQL Server 2005 SP3 housing SAP

CTE:

WITH TaktValues ([Counter], NODE, PLNNR) AS
(
SELECT
MAX(plpo1.ZAEHL) AS [Counter], MAX(plpo1.PLNKN) AS NODE, plpo1.PLNNR
FROM
etl.PLPO plpo1
GROUP BY plpo1.PLNNR

[Code] ....

Error:

Msg 8180, Level 16, State 1, Line 1
Statement(s) could not be prepared.

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1008.AUFNR" could not be bound.

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1008.AUFNR" could not be bound.

View 9 Replies View Related

Select From Linked Server Using Join, The Multi-part Identifier Could Not Be Bound.

Nov 6, 2006

Hello,

i am facing a bizarre problem, accessing data from a remote server which has been linked to my sql.
My SQL server is 2005 and the remote server is SQL 2000.
i have linked the remote server (called LinkedServer) so that when i run this query:
SELECT * FROM LinkedServer.SomeDB.dbo.SomeTable
executes successfully! However, when i run a similar query like this:
SELECT Column1 AS Col1,
LinkedServer.SomeDB.dbo.SomeTable.Column2 as Col2,
Alias.Column3 as Col3
FROM LinkedServer.SomeDB.dbo.SomeTable
INNER JOIN LinkedServer.SomeDB.dbo.SomeOtherTable1 ON LinkedServer.SomeDB.dbo.SomeTable.Column3 = LinkedServer.SomeDB.dbo.SomeOtherTable1.Column3

INNER JOIN LinkedServer.SomeDB.dbo.SomeOtherTable2 AS Alias
ON LinkedServer.SomeDB.dbo.SomeTable.Column3 = Alias.Column3

It gives me this error:
The multi-part identifier "LinkedServer.SomeDB.dbo.SomeTable.Column2" could not be bound.
The multi-part identifier "LinkedServer.SomeDB.dbo.SomeTable.Column3" could not be bound.
I have noticed that this error is generated only for the selected columns whose path has either been repeated (e.g. "LinkedServer.SomeDB.dbo.SomeTable.Column2" as opposed to "Column2") or for columns which are from aliased tables.

What is going on?!?!?!??!?!?!

Any Help would be tremendously appreciated!!!! 8..)

View 8 Replies View Related

Is There Away To Reference Global Variables In A Lookup Transformation That Are Set Outside A Data Task Flow?

Mar 31, 2008



The logic I am trying to recreate via SSIS is the following SQL statement:

insert into db3.dbo.targettable1 -- Target database table
(SiteC,
Objecte,
Attrib1)

select distinct ?,
?,
from ? -- Source database table
join dbo.targettable2 c1 -- Target database table
on c1.Alias = ? and
c1.CSetID = ? and
c1.FacID = (select f.PFacID
from dbo.Fac f
where f.FacID = ?)
where not exists (select * from dbo.targettable2 c -- Target database table
where c.Alias = ? and
c.FacID = ? and
c.CSetID = ?)


I have an OLE DB Source that consists of an expression to approximate the following portion of the Above Select statement:

Select ?,
from ? -- Source database table and

The package has 2 global variables User:CSetID and User::FacID whose scope is global to the package and whose values are set within a Foreach Loop Container outside of the Data Flow Task

I was trying to reference the 2 global variables within the Looup Transformation to recreate the following portion of the SQL statement.but encounter errors:



join dbo.targettable2 c1 -- Target database table
on c1.Alias = ? and
c1.CSetID = ? and
c1.FacID = (select f.PFacID
from dbo.Fac f
where f.FacID = ?)


In the Advanced Editor window of Lookup Transaction

select * from
(select * from [dbo].[targettable2 ]) as refTable
where [refTable].[Alias] = ? and [refTable].[FacID] = ? and
[refTable].[CSetID] = ?



Is there away to reference global variables in a Lookup Transformation that are set outside a Data Task Flow?

View 3 Replies View Related

Login Failed For User 'NT AUTHORITYANONYMOUS LOGON' For Insert Reference Using New Linked Server

Mar 23, 2006

I get this error when trying to alter a stored procedure that has an insert statement referencing a new linked server I created:

INSERT INTO [servername].databasename.dbo.DirectReport
...


Msg 18456, Level 14, State 1, Procedure Get_Direct_Pay_Move_Data, Line 17
Login failed for user 'NT AUTHORITYANONYMOUS LOGON'.

I added Administrators and my logon to the permissions of my linked server but still get this error when it tries to save my stored proc...the one which has that insert.

View 4 Replies View Related

Need Help Creating A Temporary Table In MS SQL Server.

Oct 18, 2006

Hello,

I am working on a webapp using VB.net

Right now I am writing to a sql table during a process where the end user
starts entering the contents for a file that is going to be generated once he
finishes entering the data, but the problem is that if more than one user is
doing the same process the data would get mixed up.  To avoid this I
thought in creating a temporary table (its name will consist of a string
and the current date time). 

 I would like to see any tutorial
about creating and working with temp tables.  Or if you have any
suggestions, I will appreciate them.  Thanks

View 1 Replies View Related

Secure Parts Of A Table

Sep 30, 2007

This is the thread
http://msdn2.microsoft.com/en-us/library/ms998292.aspx

Here it mentions the following
Deployment Considerations
When using Windows authentication to connect to SQL Server in production
environments, consider the following:

Use a custom service account.
Create a SQL Server login for a Windows group.
Assign database permissions to a database role.
Use a Custom Service Account

This is my problem we are trying to convert all our web pages to use Windows Authenication.
DOMAINWEBGROUP (for example).

Tracey and Jack part of this group
But sometimes there may be anothers added to this say John

The security comes from SQL right now i give data reader to the database.

Example
1. ASP.NET uses the service account DOMAINWEBGROUP
2. Assign WEBGROUP to database PERSONEL
Table Employees
Salary
Web Page
Lets say Tracey logs into the web page.....and i have two pages
1. Employess
2. Salary

As the WEBGROUP is data reader viola Tracey sees all salary information.
Im trying to figure out that only Tracey can see Employees

But im not seeing the relationship when using WEBGROUP

Is there a way in SQL to say yes we have the DOMAINWEBGROUP
but in sql also put in Tracey and know that Tracey is part of DOMAINWEBGROUP
So that in my tables i can only give tracey part of this employee table (say the first name last name) and not salary information. (I know how to use the roles).

The part im confused about is the mapping WEBGROUP to tracey in sql as the web developers only pass in WEBGROUP

View 6 Replies View Related

SQL Server 2008 :: Creating Primary Key On Temporary Table?

Apr 30, 2015

Environment: Microsoft SQL Server Standard Edition (64-bit), 10.0.5520.0

I was doing a code review for another developer and came across this code:

CREATE TABLE dbo.#ABC
(
ReportRunTime DATETIME
,SourceID VARCHAR(3)
,VisitID VARCHAR(30)
,BaseID VARCHAR(25)

[Code] ....

This EXECUTES with no error or warning message.However, if I change this to CREATE the PK in an ALTER TABLE statement, I get the (expected by me) error:

CREATE TABLE dbo.#ABC
(
ReportRunTime DATETIME
,SourceID VARCHAR(3)
,VisitID VARCHAR(30)
,BaseID VARCHAR(25)
,OccurrenceSeqID INT

[code]...

==> Msg 8111, Level 16, State 1, Line 17 Cannot define PRIMARY KEY constraint on nullable column in table '#ABC'.

==> Msg 1750, Level 16, State 0, Line 17 Could not create constraint. See previous errors.

(note: As the #ABC table is an actual copy of a few of the columns in a "permanent" table, I will likely change the definition as follows such that the columns are defined to match the names / datatypes / NULLability:

SELECT TOP 0
CAST('01-01-1980' AS DATETIME) AS [ReportRunTime]
,SourceID
,VisitID
,BaseID
,OccurrenceSeqID

[Code] .....

View 9 Replies View Related

Building A Parts Table With Multiple Catagories

Mar 14, 2008

I am trying to figure out the best way to build a table that will hold information about our inventory of parts. We have several issues that I have been struggeling with trying to make this work. First capturing the basic part information is a no brainer, where I am having some questions is with how to assign categories, subcategories for each of these parts. The challenge comes because each part can belong to multiple categories and subcategories. For example we have 5 main items that would have categories, subcategories, parts. For example:

Item: Trailer
Model: model1, model2, model3
Category: Chassis
Subcategory: Upper frame, lower frame, electrical
Part: could be any thing that falls under one of the subcategories

Item: Trailer
Model: model1, model2, model3
Category: Gen set
Subcategory: engine, power, electrical
Part: could be any thing that falls under one of the subcategories

repeat...

My main items are trailer, shelter, power, heat, lights. Under the trailer and shelter items parts can belong all models or just a couple or just one model. My thought was to create a table for each item, ie: TrailerModels, ShelterModels which would have 100 plus columns, 1 column for each model, using a bit datatype to show which parts could belong to which model. This however seems to be quite a bit of work, because in order to use the models to thin down lists when searching for an item it would have query this table as well as the category and subcategory tables.

Anyone have some feedback about how I should approach this? I don't know if I was able to communicate the specifics of this very well but I can clear up details if anyone wants to throw some feedback my way.

Thanks!





yAy

View 3 Replies View Related

SQL Server Admin 2014 :: Create Temporary Table With Dynamics Column

Jun 10, 2014

I have created a stored procedure for retrieving column name, as shown below

CM_id, CM_Name, [Transaction_Month], [Transaction_Year], [Invoice raised date],[Payment Received date],[Payout date],[Payroll lock date]

Now I am trying to create a temporary table using the above generated coluimns from Stored Procedure with datatype.

View 3 Replies View Related

SQL Server Admin 2014 :: Identify Table Made On Temporary Basis Are Not Used?

Sep 9, 2015

In the Operating environment databases, may be made tables in the database on a temporary basis but they are still yet and they are not removed, how to identify tables that have been made on a temporary basis are not used (don’t have any read & write records)?

View 4 Replies View Related

The OLE DB Provider MSDAORA For Linked Server .... Does Not Contain The Table COUNTRY. The Table Either Does Not Exist Or The Current User Does Not Have Permissions On That Table.

Jun 13, 2006

I am using SQL Server 2005 and trying to create a linked server on Oracle 10. I used the commands below:
EXEC sp_addlinkedserver
@server = 'test1',
@srvproduct = 'Oracle',
@provider = 'MSDAORA',
@datasrc = 'testsource'
exec sp_addlinkedsrvlogin
@rmtsrvname = 'test1',
@useself = 'false',
@rmtuser='sp',
@rmtpassword='sp'
 
When I execute
select * from test1...COUNTRY
I get the error. "The OLE DB provider "MSDAORA" for linked server "...." does not contain the table "COUNTRY". The table either does not exist or the current user does not have permissions on that table."
The 'sp' user I am connecting is the owner of the table. What could be the problem ?
Thanks a lot.

View 3 Replies View Related

What Is The Difference Between: A Table Create Using Table Variable And Using # Temporary Table In Stored Procedure

Aug 29, 2007

which is more efficient...which takes less memory...how is the memory allocation done for both the types.

View 1 Replies View Related

Possible To Have Temporary Rows In A Non-temporary Table? Lifespan On Rows..

Mar 14, 2004

I have a table that includes the html-output of different parts of my pages. This table grows very big very fast, and rows older than 24 hours are useless.

My question is if it is possible to have temporary rows, whose are automatically deleted after these 24 hours? And then how to accomplish that?

View 2 Replies View Related

Unique Identifier Or Int For Table ID

Feb 29, 2008

I am working on some tables and would like to know which is best way to go when deciding what Type to use for Unique ID in my tables please. Int  Or uniqueIdentifier? Or is it all the same??

View 11 Replies View Related

Transact SQL :: Find All Stored Procedures That Reference Oracle Table Name Within Server OPENQUERY Statement

Aug 10, 2015

One of our Oracle Tables changed and I am wondering if there's any way that I can query all of our Stored Procedures to try and find out if that Oracle Table Name is referenced in any of our SQL Server Stored Procedures OPENQUERY statements?

View 2 Replies View Related

Append Query From Access Table To Linked SQL Server Table Failing

Jun 18, 2004

Strange one here - I am posting this in both SQL Server and Access forums

Access is telling me it can't append any of the records due to a key violation.

The query:

INSERT INTO dbo_Colors ( NameColorID, Application, Red, Green, Blue )
SELECT Colors_Access.NameColorID, Colors_Access.Application, Colors_Access.Red, Colors_Access.Green, Colors_Access.Blue
FROM Colors_Access;

Colors_Access is linked from another MDB and dbo_Colors is linked from SQL Server 2000.

There are no indexes or foreign contraints on the SQL table. I have no relationships on the dbo_ table in my MDB. The query works if I append to another Access table. The datatypes all match between the two tables though the dbo_ tables has two additional fields not refrenced in the query.

I can manually append the records using cut and paste with no problems.

I have tried re-linking the tables.

Any ideas?
Thanks,
Brad

View 4 Replies View Related

Retrieving Autonum / IDENTIFIER Value From SQL Table Using DAO.

Apr 11, 2006

Hello,I am in the midst of converting an Access back end to SQL Server Express.The front end program (converted to Access 2003) uses DAO throughout. InAccess, when I use recordset.AddNew I can retrieve the autonum value for thenew record. This doesn't occur with SQL Server, which of course causes anerror (or at least in this code it does since there's an unhandled NULLvalue). Is there any way to retrieve this value when I add a new recordfrom SQL server or will I have to do it programmatically in VB?Any direction would be great.Thanks!

View 17 Replies View Related

Table Names In Stored Procedures As String Variables And Temporary Table Question

Apr 10, 2008

How do I use table names stored in variables in stored procedures?




Code Snippetif (select count(*) from @tablename) = 0 or (select count(*) from @tablename) = 1000000





I receive the error 'must declare table variable '@tablename''

I've looked into table variables and they are not what I would require to accomplish what is needed.
After browsing through the forums I believe I need to use dynamic sql particuarly involving sp_executesql. However, I am pretty new at sql and do not really understand how to use this and receive an output parameter from it(msdn kind of confuses me too). I am tryin got receive an integer count of the records from a certain table which can change to anything depending on what the user requires.




Code Snippet

if exists(Select * from sysobjects where name = @temptablename)
drop table @temptablename




It does not like the 'drop table @temptablename' part here. This probably wouldn't be an issue if I could get temporary tables to work, however when I use temporary tables i get invalid object '#temptable'.

Heres what the stored procedure does.
I duplicate a table that is going to be modified by using 'select into temptable'
I add the records required using 'Insert into temptable(Columns) Select(Columns)f rom TableA'
then I truncate the original table that is being modified and insert the temporary table into the original.

Heres the actual SQL query that produces the temporary table error.




Code Snippet
Select * into #temptableabcd from TableA

Insert into #temptableabcd(ColumnA, ColumnB,Field_01, Field_02)
SELECT ColumnA, ColumnB, Sum(ABC_01) as 'Field_01', Sum(ABC_02) as 'Field_02',
FROM TableB
where ColumnB = 003860
Group By ColumnA, ColumnB

TRUNCATE TABLE TableA

Insert into TableA(ColumnA, ColumnB,Field_01, Field_02)
Select ColumnA, ColumnB, Sum(Field_01) as 'Field_01', Sum('Field_02) as 'Field_02',
From #temptableabcd
Group by ColumnA, ColumnB




The above coding produces

Msg 208, Level 16, State 0, Line 1

Invalid object name '#temptableabcd'.

Why does this seem to work when I use an actual table? With an actual table the SQL runs smoothly, however that creates the table names as a variable problem from above. Is there certain limitation with temporary tables in stored procedures? How would I get the temporary table to work in this case if possible?

Thanks for the help.


View 6 Replies View Related

SQL Server 2012 :: Convert Parts Of String To Int

May 2, 2014

I have log files that I am loading into a table with duration data in the format "xx hrs xx min xx sec". Only the parts that are required will be there so if duration is only 2 seconds , the column will show "2 sec".

I am trying to get the duration into in to do some analysis on it and I have come up with this query so far which returns the correct data but i am wondering if there is a way to do what I am trying in a more readable format.

CREATE TABLE #tmp(duration VARCHAR(20))

INSERT INTO #tmp
VALUES ('1 hrs 20 min 12 sec'), --4812 sec
('48 sec'), --48 sec
('39 min 1 sec'), --2341 sec
('11 hrs 1 min 1 sec'), --39661 sec
('59 min 0 sec'), --3540 sec
('2 min 50 sec') --170 sec

And this is what I have so far

SELECT CASE
WHEN CHARINDEX('hrs', duration, 1) <> 0 THEN CAST(SUBSTRING(duration, 1, CHARINDEX(' hrs', duration, 1) - 1)AS int) * 3600 + CAST(SUBSTRING(duration, CHARINDEX(' hrs', duration, 1) + 5, CHARINDEX(' min', duration, 1) - 7)AS int) * 60 + CAST(SUBSTRING(duration, CHARINDEX(' min', duration, 1) + 5, CHARINDEX(' sec', duration, 1) - 14)AS int)
WHEN CHARINDEX('hrs', duration, 1) = 0

[Code] ...

I ultimately plan on converting this to a SSIS expression so that is why I am looking to simplify it.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved