[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL Query with quoted identifier

Posted on 2012-03-21
13
Medium Priority
?
487 Views
Last Modified: 2012-08-14
i'm trying to use the sp_estimate_data_compression_Savings

to get all tables;

i'm getting an error:

i want it to look like this:

EXEC sp_estimate_data_compression_savings 'dbo', 'fact_WebActivity', NULL, NULL, 'ROW' ;

Trying this: so that i get all tabels

select 'EXECUTE sp_estimate_data_compression_savings ''dbo''' + ',' + ''''+ name from sys.tables where type = 'u' + '''
0
Comment
Question by:Auerelio Vasquez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 16

Expert Comment

by:DcpKing
ID: 37749441
You have to prefix every tick (  '  ) with another, and then wrap the thing in ticks!

declare @str varchar(1000)
set @str = 'sp_estimate_data_compression_savings '
set @str = @str + '''dbo'', '
set @str = @str + '''fact_WebActivity'' '
set @str = @str + ', NULL, NULL, ''ROW'' ;'
--print @str       --do this to check that it's right !
exec @str

I did it in four steps to show how more clearly.
0
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 37749485
select 'EXEC sp_estimate_data_compression_savings ''dbo,''' + name  + ''',NULL,NULL,''ROW''' from sys.tables where type = 'u'

Open in new window

0
 
LVL 16

Expert Comment

by:DcpKing
ID: 37749497
(oops - missed parens around the @str - sorry!)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:netjgrnaut
ID: 37749516
Oh, I thought you were trying to build a literal set of command lines, to execute later (based on your SELECT statement shown).

The select statement I posted above produces the following output...

EXEC sp_estimate_data_compression_savings 'dbo,'r3_tracker-20110926_baseline',NULL,NULL,'ROW'
EXEC sp_estimate_data_compression_savings 'dbo,'srcBL_GroupMembers',NULL,NULL,'ROW'
EXEC sp_estimate_data_compression_savings 'dbo,'r3_tracker-20110926_rit3010422',NULL,NULL,'ROW'
EXEC sp_estimate_data_compression_savings 'dbo,'srcBL_Groups',NULL,NULL,'ROW'
EXEC sp_estimate_data_compression_savings 'dbo,'r3_tracker-20110927_rit301(2725-3311-3393)',NULL,NULL,'ROW'
EXEC sp_estimate_data_compression_savings 'dbo,'srcBL_InteractiveRights',NULL,NULL,'ROW'

Open in new window

0
 
LVL 1

Author Comment

by:Auerelio Vasquez
ID: 37749972
@netjgrnaut

You are correct in your assumption. That's what i wanted. The only issue:

I need the second tick mark around dbo like 'dbo'

to look like this

EXEC sp_estimate_data_compression_savings 'dbo','fact_WebActivity',1,NULL,'Page'
0
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 37749977
Whoops. Put two ticks after dbo, before the period. That should do it.
0
 
LVL 1

Author Comment

by:Auerelio Vasquez
ID: 37752773
ok. so this worked .  i was overthinking it. One last question regarding this, how is the best way, to get each line returned from all of these exec statements, into one table ?

select 'EXEC sp_estimate_data_compression_savings ''dbo'',''' + name  + ''',NULL,NULL,''ROW''' from sys.tables where type = 'u'
0
 
LVL 6

Accepted Solution

by:
netjgrnaut earned 2000 total points
ID: 37752787
select 'EXEC sp_estimate_data_compression_savings ''dbo'',''' + name  + ''',NULL,NULL,''ROW''' as SQLCMD into doCommands from sys.tables where type = 'u'

Open in new window


...will create a table named doCommands with a single column (SQLCMD) where each row is one command returned from the query.
0
 
LVL 1

Author Comment

by:Auerelio Vasquez
ID: 37753347
I apologize, what i meant, was the results from all of those queries, into one table, one row at a time. this give all the commans, which is how i asked it, but i wanted the results. these come out one execution at a time. is there a way, to that result, and insert into a table. i thought of a cursor for this, but i can't get my hands around all the tick marks, to put into a @String varable.....
0
 
LVL 1

Author Comment

by:Auerelio Vasquez
ID: 37753352
i can put this into another question, so i can award these points, if you like.
0
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 37753380
A new topic would probably be best, to help those looking for specific answers in the future.
0
 
LVL 1

Author Comment

by:Auerelio Vasquez
ID: 37753780
Can I direct that to u somehow?
0
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 37753795
I'll check your profile for open questions later this afternoon... but there may be better folks to provide you with a quick answer.

Thanks for the vote of confidence!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question