Working With SQLCMD: Variables And Table Permissions

Jan 3, 2008

Nice simple problem, trying to set the guest user with SQLCMD to have select permissions on an object:
-- Code below
-- Line below should read "colon"setvar MAD guest
: setvar MAD guest

SELECT $(MAD)

GRANT SELECT ON OBJECT::dbo.ErrorLog TO $(MAD)



Unfortunatly I keep getting the following error being thrown:

Msg 207, Level 16, State 1, Line 1

Invalid column name 'guest'.



Any ideas?

Thanks,

d

View 1 Replies


ADVERTISEMENT

SQLCMD Error - Working With Variables And Synonyms

Jan 3, 2008

Hi All,

Been doing some testing with SQLCMD and variables for installation scripts, enclosed below is some source code.
The one problem, I've been getting is the following error:

Incorrect syntax near 'certification'

This has been tested only in SSMS utilising the run in SQLCMD mode.

This error only occurs on the SQLCMD variable replacement, where it replaces $(Cert_Schema) for the word Certification.
Running the CREATE Synonym with the word Certification hard-coded into the script works.

Any ideas?
Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) Mar 23 2007 16:28:52 Copyright (c) 1988-2005 Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)

Best Regards,

D


USE [Testing]

GO

/****** Object: Table [certification].[Table_1] Script Date: 01/03/2008 11:22:48 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [certification].[Table_1](

[PKId] [smallint] NOT NULL,

[Name] [nchar](10) NULL,

CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED

(

[PKId] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

--- SQLCMD Script below:
-- line below should read, colon setvar cert_schema 'certification'

etvar Cert_Schema 'certification'
-- The line below fails to work for some reason

CREATE SYNONYM crt_asa FOR $(Cert_Schema).Table_1

DROP SYNONYM crt_asa

-- Hard-coded equivilant line works

CREATE SYNONYM crt_asa FOR certification.Table_1

DROP SYNONYM crt_asa

View 3 Replies View Related

Working With Variables

Jan 3, 2008

Hi all,

I'm trying to intialize a variable to a value from a table. and I'm not sure how to avoid the syntax error I'm getting. Could anyone help????? below is the way I have it written.

DECLARE @number int
SET @number = SELECT column FROM table1


Thanks,

Happy new Year

View 4 Replies View Related

ASP.NET Membership Stops Working (Permissions?)

Oct 10, 2006

I've been coding for a few weeks now, building an ASP.NET application.  ran the aspnet_regsql.exe wizard and it created my table and procedures correctly within the live SQL 2005 server being run by my host (ASPNIX.COM).  I've been able to run my app just fine locally saving to my remote SQL server.  However, now that I've moved my code onto my hosted server, my app stopped working.  You would think this would "jus work" since I've been using the same SQL server throughout...BUT NOoooo!  I've scoured the net trying to find any hint about what might be happening.  The ONLY thing I've been able to find is a story in the May issue of asp.netPRO that says "Once the scripts have been executed, grant the user account used to access the database from the Web application Execute permissions on all the new stored procedures and Selection permissions on the views that were created"This may be my problem, but I haven't figured out how to accomplish this.  Within the SQl Server Management Studio Express, I can pull up the properties of each stored procedure and place a check next to my "USER" account.  However it does not appear to be saved.My symptoms at this point are:It will not log me in under accounts I'd already created.

View 7 Replies View Related

Permissions For Developers Not Working After 2005 Upgrade

Feb 1, 2006

Prior to our move to 2005...permissions were granted to developers by adding them to the following fixed database roles...db_ddladmin, db_datareader, db_datawriter, and db_securityadmin. They created their objects using 'dbo' as the owner.

After upgrading to 2005, suddently they are having difficulty accessing their objects with this same security. Do they need permissions on the dbo schema?

View 7 Replies View Related

ALTER TABLE From Sqlcmd Script

Aug 10, 2006

Hi,I'm trying to add a column to a table, then update that column with aquery. This is all within a single batch. Sqlcmd gives me an error onthe update, saying "invalid column xxx", because it doesn't know thecolumn got added. We used to get around this in "osql" by using theEXECUTE command, like: EXEC ("ALTER TABLE tbl ADD newfield varchar(255)not null default ' '")However, it looks like sqlcmd actually checks each query within thescript before it starts running, and throws the error because the fieldisn't there at the time.If need be I can just do a SELECT INTO and add the column there, butit's a pain in the butt and I'm moving a LOT of data just to do what Iwant. And no, I can't go back to where the table is created and addthe column. Does anyone have any suggestions? TIA!- Jeff

View 2 Replies View Related

Table Permissions Versus View Permissions

Aug 2, 2006

Using SQL Server 2k5 sp1, Is there a way to deny users access to a specific column in a table and deny that same column to all stored procedures and views that use that column? I have a password field in a database in which I do not want anyone to have select permissions on (except one user). I denied access in the table itself, however the views still allow for the user to select that password. I know I can go through and set this on a view by view basis, but I am looking for something a little more global.

View 5 Replies View Related

Export Table To A Text File Using Sqlcmd

Mar 26, 2008

How do i use sqlcmd to export the rows in a table to a comma-delimited text file?

Thanks,
Sean

View 2 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

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

Update One Table When Records Inserted In Another Table - Variables In Trigger

May 19, 2014

I am trying to update one table when records are inserted in another table.

I have added the following trigger to the table “ProdTr” and every time a record is added I want to update the field “Qty3” in the table “ActInf” with a value from the inserted record.

My problem appears to be that I am unable to fill the variables with values, and I cannot understand why it isn’t working, my code is:

ALTER trigger [dbo].[antall_liter] on [dbo].[ProdTr]
for insert
as
begin
declare @liter as decimal(28,6)

[Code] ....

View 4 Replies View Related

Table Permissions

Oct 4, 2001

is it possible to have 1 column in a table that is the only updateable column in the table?

View 2 Replies View Related

Set Permissions On A Table

Feb 4, 2007

I want to set permissions on two tables...i dont want to allow delete or truncate statements to be executed on those tables. how can i do it....(sqlserver 2005)

View 1 Replies View Related

Table Variables

Feb 2, 2006

Hello,I am writing a function that uses two table variables. The structures ofboth are shown here:DECLARE @workdates TABLE (conflict CHAR(1),workdate SMALLDATETIME)DECLARE @existing TABLE (workdate SMALLDATETIME)I need to do an update on the first table:UPDATE @workdatesSET conflict = 'X'FROM @existing sWHERE workdate = s.workdateI am concerned that the unqualified 'workdate' in the WHERE clause willgive me an ambiguous column reference. Is this SQL statement valid?Thanks,Andrew

View 3 Replies View Related

TABLE Variables

Jul 20, 2005

Hey everyone,I read in a SQL Server book that you can now create a tablevariable.DECLARE @TMP TABLE (list of fields)Then you can you can use the statementINSERT INTO @TMPSELECT (whatever).I've tried it and it works. The book also says that youshould be able to pass these variables between storedprocedures and functions. Problem is, when I try todeclare the variable at the top of the procedure, thesyntax checker hates it.Anyone else out there try this out?SAM

View 1 Replies View Related

Table Variables

May 9, 2007

Will reporting services allow the use of table variables in the SQL query?

View 1 Replies View Related

Table Variables

Jun 11, 2007

I want to querry a table based on the input of a form, I have tables Monday, Tuesday ect., and want to display the records for Monday if the user selects Monday in a menu. I need to delcare a table name but am not sure how?

DELCARE @myVar char(20)
SET myVar = Request.Form("select2");



"SELECT * FROM @myVar"



View 2 Replies View Related

Table Variables

Apr 28, 2008



I know user defined global table variables are not allowed in sql. I'm trying to avoid using temporty tables for speed reasons. I have a function in which a table variable is defined, and a function within that function that needs to call that table variable. Any ideas?

Thanks

View 1 Replies View Related

Table Variables/Table Reference - Is This Possible?

Feb 28, 2005

Is it possible to do something like this in SQL:

DECLARE @TABLE table

if @GOOD = 1 BEGIN
Set @Table = Table1
END ELSE BEGIN
Set @Table = OtherTable
END

SELECT * FROM @TABLE

View 1 Replies View Related

Why Not Allow Select Permissions To Table

May 19, 2004

I have always set up sql security for reporting to have select permissions on the tables to be used in the reports. I'm told by my coworkers that this is not advisable and I should only use stored procedures for reporting. I use stored procedures for all application duties, insert/update/delete etc but find with reporting it's much easier to just provide select permission to the tables. The only drawback to my method appears to me to be a user could conceivably view all data in tables while with the stored procedure one can limit what is being viewed. Anything else I'm missing? Thanks.

View 2 Replies View Related

Truncate Table Permissions

Mar 22, 2006

Does anybody know of a way to allow non-administrators to execute the truncate table statement?

I have developers that from time to time need to move data between their databases usinge the DTS wizard. Most of their tables have identity columns and in order retain the identity seed, they need to click on the option to enable identity insert. This option isn't available to non administrators.

View 4 Replies View Related

Drop Table Permissions

Jul 12, 2000

I have a group that has select, insert, update, delete permissions and I have a user in that group that
needs permissions also to drop tables.

does that login need to be aliased to dbo - which is in public -- do I then to give puboic all the other permissions.

Is there a way to just give one login all permissions including dropping tables??

Help!!

View 1 Replies View Related

Replication Table Permissions

Apr 19, 2004

Is there a way to replicate the table permissions from publisher to
subscriber? I noticed that when replication takes place, the permissions
that were set up on tables on the subscriber are wiped out. I need the permissions to be send to the subscriber automatically.

View 8 Replies View Related

Scripting Table Permissions

Sep 25, 2007

I have give permission to one SQL Server 2005 user account on a table in my database. i want to script that or any permission i have on table.

my question is, how to create that script in SQL server 2005. if i right click the table -> select "script table as" and select "create to" new query editor, it only creates script for creating the table and doesnt include the permission any account have on that table.....how to do that ? plz help

View 1 Replies View Related

Table And View Permissions

Aug 2, 2007

I have a list of users that I want to restrict access to tables in a database. The goal is to allow the users to use select statements on the views instead of the tables. How can this be accomplished?

View 14 Replies View Related

Table Variables And Calculations

May 4, 2007

 So, I've got a problem with using table variable "fields" and a simple variable in calculations. It ain't workin'. See the bolded code below. When I run the SP, it returns 0 for those values. Anyone got any clues? Is this a table variable limitation?  ALTER PROCEDURE YearlyTotalsInPercentages(@Year int) ASBEGINDECLARE @TotalSum intDECLARE @Totals TABLE
(
CBDCYearlyTotals int, ProductLine varchar(50))INSERT INTO @Totals (CBDCYearlyTotals, ProductLine)SELECT SUM(dbo.Main.Hours), dbo.Project.ProductLineFROM dbo.Main INNER JOIN dbo.Department ON dbo.Main.DeptNo = dbo.Department.DeptNo INNER JOIN dbo.Project ON dbo.Main.ProjectNo = dbo.Project.ProjectNoWHERE dbo.Main.UserID LIKE 'CI%' AND dbo.Project.ControlLocation = 'IND' AND DATEPART(yyyy, dbo.Main.DataDate) = @Year AND dbo.Main.Active = 1GROUP BY dbo.Project.ProductLine SET @TotalSum = (SELECT SUM(dbo.Main.Hours)FROM dbo.Main INNER JOIN dbo.Department ON dbo.Main.DeptNo = dbo.Department.DeptNo INNER JOIN dbo.Project ON dbo.Main.ProjectNo = dbo.Project.ProjectNoWHERE dbo.Main.UserID LIKE 'CI%' AND dbo.Project.ControlLocation = 'IND' AND DATEPART(yyyy, dbo.Main.DataDate) = @Year AND dbo.Main.Active = 1) SELECT t.CBDCYearlyTotals AS CBDCYearlyTotals, t.ProductLine AS ProductLine, @TotalSum AS TotalSum, ROUND((t.CBDCYearlyTotals/@TotalSum) * 100, 1) AS Percentage FROM @Totals tEND
GO
  Thanks Yall

View 1 Replies View Related

Qualifying Table Variables

Jan 6, 2004

hi all!

I am using table variables instead of creating a temp table because it seems to be faster

But now I need qualify the table variable so I can join it with another table having a field with same name of a field from the table variable. U know if I can do that?

ex: with temp table

create table #tmp.... (F1...)
#tmp.f1

with table variable

declare @temp table(...
@table.f1 - can´t do it

the first question is if I can join the table variable with another table and how to do that qualifying the variable table, that is, putting the name of the var temp with the field, because the other table has a field with same name


thank to all and happiness for all 2004

View 2 Replies View Related

Dynamic SQL And Table Variables...?

Aug 23, 2004

Hello, all. I'm attempting to insert data into a table variable using dynamic SQL created at runtime.

However, with a Table variable, SQL server will not allow the EXEC method to be used in an INSERT statement.

How do I go about this?

View 2 Replies View Related

Using Variables In A Temp Table Name

May 4, 2000

I am trying to add a variable to a temporary table name. Throughout a stored procedure, I do a lot with this table. I delete, insert, update, and query this table. Is there a way to do the following without having to set the entire 'select * from ...' line as a variable? Below is what I am trying to accomplish. It all works until the select * line. Is there a way to accomplish what I am trying to do below?

Declare @table varchar(255),
@PassedID integer
set @passedID=5

set @table="test"+CONVERT(varchar(20), @passedID)

select * from @table

Thanks,
Jon

View 3 Replies View Related

Table Names And Variables

Nov 14, 2005

I have a cursor which populates a variable with the name of each user table within my DB.
I'm trying to copy the tables one at a time by using a command like this:
SELECT * INTO @NewTable FROM @OrigTable
Query analyzer tells me that there's incorrect syntax near the keyword 'INTO'.
This seems fair enough to me as I assume it's trying to put the data into the variable rather than the table name which is held within the variable. Does any know how I can get around this?
Are there any alternative ways of copying the table structure (preferable without the data)?

BTW both variables are of type char(100)

View 1 Replies View Related

Count Two Variables In Table

Aug 23, 2013

I have a table that has two columns POLICY_NUMBER and POLICY_TYPE

POLICY_NUMBER POLICY-TYPE
123 1
123 1
123 1
567 2
567 2
789 1
789 1
345 1
345 1
345 1

I need to write a script that give me the following result

policy_type_count policy_type

3 1
1 2

View 3 Replies View Related

Trigger And Table Variables

Nov 6, 2014

Can we use tables variables in triggers... if yes, any example...

View 4 Replies View Related

Table Variables And Identities

Feb 16, 2006

Can an identity be created in a table variable?

Can joins be performed between table variables to be inserted into another table variable?

Am I better of using a temporary table?

(I'm working in a stored procedure here)

Thanks in advance

View 10 Replies View Related







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