Viewing 15 posts - 106 through 120 (of 241 total)
You can't have dynamic code in the view. But you can write dynamic script (or procedure) that will generate DROP and CREATE VIEW statements (or ALTER VEW) with all your...
April 16, 2014 at 4:00 pm
There must be only one... ORDER BY... at the end of your query.
April 15, 2014 at 10:37 am
For existing objects you can search sys.sql_modules:
SELECT
o.object_id
,SchemaName = s.name
,ObjectName = o.name
,o.[type]
,m.[definition]
FROM sys.objects o
...
April 14, 2014 at 3:53 pm
Perhaps you should choose "Operating System" for the Type as sqlcmd is a command line utility?
April 14, 2014 at 1:58 pm
You can't sort on posteddate+companydid. You get the error, right?
So, you need to either convert posteddateto varchar and then concatenate:
CONVERT(char(8), posteddate, 112) + companydid
Or change your dynamic code to...
April 12, 2014 at 8:46 am
You can't convert string that contains non-numeric characters to INT. If you need to concatenate then you have to convert other datatypes to varchar.
What are you trying to achive? Are...
April 11, 2014 at 4:07 pm
a4apple (4/10/2014)
Nita Reddy (4/10/2014)
how do I pass day 16 in the code
What do you mean to say, when you want to pass 16 in the code. It's not even a...
April 11, 2014 at 3:51 pm
The error occures when you build your dynamic query or when you execute it? What datatype is @OrderType? Assuming it's a VARCHAR, this
DECLARE @OrderBy VARCHAR(20) = 'Posteddate'
DECLARE @OrderType VARCHAR(20)...
April 11, 2014 at 3:24 pm
Check this article: http://www.sqlservercentral.com/articles/T-SQL/62159/
April 11, 2014 at 2:19 pm
Your dynamic code should look like this:
declare @CurrMo Varchar(30)
declare @CurrYe Varchar(30)
DECLARE @TSQL varchar(8000)
set @CurrMo = Month(dateadd(day,-1,getdate()))
set @CurrYe = Year(dateadd(day,-1,getdate()))
SELECT @TSQL = '
INSERT INTO [Srvr2].[dbo].[tbl_Rent_Uti2]
([Year],
[Month],
[Utilperiod],
[PL],
[BL],
[Store],
[Region],
[UnitsOR],
[FleetOR],
[UnitsTotal],
[NBVTotal],
[FleetTotal])
Select Year, Month...
April 11, 2014 at 12:40 pm
The error you are getting is because this is syntactically invalid:
INSERT INTO TableA
SELECT @TSQL = 'select * from TableB'
April 11, 2014 at 11:37 am
You need to include the whole thing (including INSERT INTO part) into the dynamic code.
April 11, 2014 at 11:28 am
You can use OPENROWSET. Assuming you have ACE driver installed:
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\Test\MySheet.xlsx',
'select * from [Sheet1$]')
Make sure the file is not opened by any other program.
April 11, 2014 at 10:52 am
You do assignment, here:
SELECT @TSQL =
April 11, 2014 at 10:40 am
Should be in the job history (under SQL Server Agent if you use Object Explorer).
Or check here: msdb.dbo.sysjobhistory
April 11, 2014 at 9:49 am
Viewing 15 posts - 106 through 120 (of 241 total)