USE [MiddlewareProxyDB]
GO

-- Migration script to add SessionId computed column to existing StandardSurvey table
-- Run this script if the table already exists in your database

-- Step 1: Add the computed column SessionId with length limit to avoid index warnings
ALTER TABLE [dbo].[StandardSurvey]
ADD [SessionId] AS (LEFT(CONCAT([RouterCallKeyDay], REPLACE(REPLACE(RTRIM([RouterCallKey]), ' ', ''), '"', '')), 100)) PERSISTED
GO

-- Step 2: Create index on the computed SessionId column for better performance
-- Using varchar(60) ensures we stay well under the 1700-byte limit
CREATE NONCLUSTERED INDEX [IX_StandardSurvey_SessionId] 
ON [dbo].[StandardSurvey] ([SessionId])
INCLUDE ([ANI], [AgentSkillTargetID], [FeedStatus])
GO
